Modulo Summation——UPC
题目描述
You are given N positive integers a1,a2,…,aN.
For a non-negative integer m, let f(m)=(m mod a1)+(m mod a2)+…+(m mod aN).
Here, X mod Y denotes the remainder of the division of X by Y.
Find the maximum value of f.
Constraints
·All values in input are integers.
·2≤N≤3000
·2≤ai≤105
输入
Input is given from Standard Input in the following format:
N
a1 a2 … aN
输出
Print the maximum value of f.
样例输入
3
3 4 6
样例输出
10
提示
f(11)=(11 mod 3)+(11 mod 4)+(11 mod 6)=10 is the maximum value of f.
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
start{int n=read;int all=-n,temp;for(int i=0;i<n;i++){temp=read;all+=temp;}cout<<all;end;
}/**************************************************************Language: C++Result: 正确Time:1 msMemory:2024 kb
****************************************************************/
Modulo Summation——UPC相关推荐
- AtCoder - 4172 Modulo Summation 贪心
开始想复杂的了 仔细观察样例后发现这个数 其实就是所有的数的LCM-1吗 只有LCM-1 对所有数取模的时候才能对所有数得到MOD = a[i]-1: 那么一个X%Y得到的最大值就是Y-1 于是得到了 ...
- Modulo Summation atcoder abc103
此题链接 题意,求f(m)的最大值,f(m)=(m mod a1)+(m mod a2)+-+(m mod an). 思路:想一想我们要求f(m)的最大值,那我们是不是要满足每一个数都能取到最大值.每 ...
- UPC第41场,第42场部分题解
UPC第41场,第42场部分题解 第41场 A: LR Constraints We have N cards arranged in a row from left to right. We wil ...
- UPC第38,39,40场部分题解
UPC第38,39,40场部分题解 第38场 A. Bovine Alliance Description Bessie and her bovine pals from nearby farms h ...
- UPC个人训练赛第十五场(AtCoder Grand Contest 031)
传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...
- Summation Order
This note is for my students (first year) who got confused in class when I showed the proof of theor ...
- codeforces 7.22 F Pairwise Modulo
codeforces 7.22 F Pairwise Modulo 给出n个数的数列a,每个数互不相同且都小于3e5,求出qk=∑1<=i,j<=kaimodajq_k=\sum_{1&l ...
- 北邮OJ 884. 16校赛-Average Modulo
时间限制 5000 ms 内存限制 65536 KB 题目描述 We define function g on an array as: g([a0,a1,⋯,an−1])=(Σn−1l=0al) m ...
- 【SPOJ】Power Modulo Inverted(拓展BSGS)
[SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...
最新文章
- SpringMVC 表单验证
- 积累有价值的seo资源提高网站优化效果
- 2021年全球数据中心调查
- 不同测试阶段,不同测试类型的区别于联系
- 微信公众平台“自定义回复”技巧
- suse linux 文件只可读,SUSE LINUX下文件系统变只读的问题解决
- ubuntu 12.04 mysql_ubuntu12.04 安装和卸载mysql
- 使用PHP对word文档进行操作的方法
- 家庭监控方案设计及施工-无线监控
- win10安装MinGW
- 电商宝:做最懂电商卖家的财务管理“小秘书”
- 手把手带你撸一个校园APP(一):项目简介
- CRM SaaS是什么?
- Android应用安全加固
- 关于人性的一些思考:如何提高员工工作热情与成就感,以及因材施教的心灵培训
- TMS320C6678开发笔记---IBL编译与分析1
- 在你人生低谷的时候,领悟到什么?
- Web 攻防之业务安全:越权访问漏洞 测试.
- 简单的银行管理系统(功能齐备)
- OpenMMLab 实战营打卡 - 第 四 课 目标检测算法基础
热门文章
- IOS-Touch ID的简单使用
- ipad未能与itunes连接到服务器,ipad无法连接itunes store怎么办
- 112358序列c语言,112358(112358的规律是什么)
- 量化投资中的神奇特点
- OpenCV python 彩色图片的三通道
- 复古派 Retropie=
- 【Agni-s Philosophy】使用的图形技术解说(后篇)Volume渲染和粒子处理
- 北京地铁月度消费总金额计算(Python版)
- 计算机桌面不同步,怎样使电脑桌面文件在不同桌面位置上显示
- 高项_第十三章项目合同管理