首页 > 其他分享 >HDU 5586 Sum

HDU 5586 Sum

时间:2022-11-09 19:00:48浏览次数:42  
标签:5586 HDU int Sum long 9999 maxn include sum


Problem Description



There is a number sequence HDU 	5586 Sum_HDU,you can select a interval [l,r] or not,all the numbers HDU 	5586 Sum_#include_02 will become HDU 	5586 Sum_HDU_03.HDU 	5586 Sum_HDU_04.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.HDU 	5586 Sum_i++_05 Next line contains n integers HDU 	5586 Sum_HDU.HDU 	5586 Sum_#include_07 It's guaranteed that HDU 	5586 Sum_#include_08.


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


求个 差值然后求个连续和最大就好了

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int n;
long long a[maxn], b[maxn], c[maxn], sum, k;

int main()
{
while (scanf("%d", &n) != EOF)
{
k = sum = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
b[i] = (a[i] * 1890 + 143) % 10007;
c[i] = b[i] - a[i];
sum += a[i];
}
long long u = 0;
for (int i = 1; i <= n; i++)
{
if (u + c[i] > 0) u = u + c[i]; else u = 0;
if (u > k) k = u;
}
printf("%I64d\n", sum + k);
}
return 0;
}



标签:5586,HDU,int,Sum,long,9999,maxn,include,sum
From: https://blog.51cto.com/u_15870896/5838304

相关文章

  • HDU 4436 str2int
    ProblemDescriptionInthisproblem,youaregivenseveralstringsthatcontainonlydigitsfrom'0'to'9',inclusive.Anexampleisshownbelow.1......
  • HDU 5264 pog loves szh I
    ProblemDescriptionPoghaslotsofstrings.Andhealwaysmixestwoequal-lengthstrings.Forexample,therearetwostrings:"abcd"and"efgh".Afterm......
  • HDU 5639 Deletion
    ProblemDescriptionG with n verticesand m edges.Everytime,youcanselectseveraledgesanddeletethem.Theedgesselectedmustmeetthe......
  • HDU 5637 Transform
    ProblemDescriptionn integersaregiven.Foraninteger x youcandothefollowingoperations:+letthebinaryrepresentationof x be ......
  • HDU 1403 Longest Common Substring
    ProblemDescriptionGiventwostrings,youhavetotellthelengthoftheLongestCommonSubstringofthem.Forexample:str1=bananastr2=ciana......
  • HDU 4658 Integer Partition
    ProblemDescriptionGivenn,k,calculatethenumberofdifferent(unordered)partitionsofnsuchthatnopartisrepeatedkormoretimes.  ......
  • HDU 5638 Toposort
    ProblemDescriptionn verticesand m edges.Youareallowedtodeleteexact k InputT indicatingthenumberoftestcases.Fore......
  • HDU 4651 Partition
    ProblemDescriptionHowmanywayscanthenumbers1to15beaddedtogethertomake15?Thetechnicaltermforwhatyouareaskingisthe"numberofpart......
  • kafka Java客户端之 consumer API 消费消息
    背景:我使用docker-compose搭建的kafka服务​kafka的简单介绍以及docker-compose部署单主机Kafka集群​​使用consumerAPI消费指定Topic里面的消息首先我们需要使用AdminA......
  • MybatisPlus Lambda表达式 聚合查询 分组查询 COUNT SUM AVG MIN MAX GroupBy
    一、序言众所周知,MybatisPlus在处理单表DAO操作时非常的方便。在处理多表连接连接查询也有优雅的解决方案。今天分享MybatisPlus基于Lambda表达式优雅实现聚合分组查询。......