转变一下思维, 求差值最大连续字段和, 因为最后结果只增不减;
#include#include #include using namespace std;#define N 100000+100typedef long long LL;const LL INF = 0x3f3f3f3f;LL num[N], transNum[N], dp[N];inline LL f(LL a){ return (1890* a +143)% 10007; }int main(){ int n; while(scanf("%d", &n) != EOF) { LL sum=0; for(int i=1; i<= n; i++) { scanf("%lld", &num[i]); sum+= num[i]; } for(int i=1; i<= n; i++) { transNum[i]= f(num[i])-num[i]; } memset(dp, 0, sizeof(dp)); LL maxsum =0; for(int i=1; i<= n; i++) { dp[i]= dp[i-1]>0? dp[i]+dp[i-1]+transNum[i]: dp[i]+transNum[i]; maxsum =max(maxsum, dp[i]); } printf("%lld\n", maxsum+ sum); } return 0; }