Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 20 Accepted Submission(s): 13
Problem Description
A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai). f(x)=(1890x+143)mod10007.After that,the sum of n numbers should be as much as possible.What is the maximum sum?
Input
There are multiple test cases.
First line of each case contains a single integer n.
(1≤n≤105)
Next line contains n integers
A1,A2....An.
(0≤Ai≤104)
It's guaranteed that
∑n≤106.
Output
For each test case,output the answer in a line.
Sample Input
2 10000 9999 5 1 9999 1 9999 1
Sample Output
19999
22033
//中文题意:
Sum
问题描述
给n个数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An,你可以选择一个区间(也可以不选),区间里每个数x变成f(x),其中f(x)=(1890x+143)mod10007f(x)=(1890x+143) mod 10007f(x)=(1890x+143)mod10007。问最后n个数之和最大可能为多少。
输入描述
输入有多组数据。
每组数据第一行包含一个整数n.(1≤n≤105)(1\leq n\leq {10}^{5})(1≤n≤105)
第二行n个整数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A1,A2....An.(0≤Ai≤104)(0\leq {A}_{i}\leq {10}^{4})(0≤Ai≤104)
数据保证 ∑n≤106\sum n\leq {10}^{6}∑n≤106.
输出描述
对于每组数据输出一行答案.
输入样例
2
10000 9999
5
1 9999 1 9999 1
输出样例
19999
22033
//虽然是中文题,但比赛时就是读不懂什么意思,还以为是拓展GCD呐,赛后看了大神的代码才真正明白题的意思。
题意就是给你n个数,你可以从这n个数里面选一个区间,(也可以不选),如果选了,那么这一区间里的数x会通过公式变成f(x),如果不选,那么x还是x(不变)。最后将这n个数求和,要求他们的和最大。。。
#include<stdio.h>
#include<string.h>
#define N 100010
int a[N];
int main()
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
int m=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
m+=a[i];
}
int ans=0,sum=0,mm=0;
for(i=1;i<=n;i++)
{
ans+=a[i];
sum=sum+(a[i]*1890+143)%10007;
if(sum-ans>mm)
mm=sum-ans;
else if(sum-ans<0)
{
sum=0;
ans=0;
}
}
printf("%d\n",m+mm);
}
return 0;
}