#include<cstdio> #define dane 200000 typedef unsigned long long ull; typedef long long ll; ull max(ll x, ll y) { return x > y ? x : y; } ull p[dane+1]; ull c[dane+1]; ull wyn[dane+1]; ull s = 0; main() { int n, m; scanf("%d%d", &n, &m); for(int i=0;i<n;i++) { scanf("%llu", &c[i]); s += c[i]; } for(int i=0;i<m;i++) { scanf("%llu", &p[i]); } for(int i=0;i<m;i++) { ull res = 0; wyn[0] = max(0,c[0]-p[i]); for(int j=1;j<=n;j++) { wyn[j]=max(wyn[j-1]+p[i],c[j]-p[i]); } for(int j = 0; j < n; j++)res += wyn[j]; printf("%llu\n", res + n*p[i] - s); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include<cstdio> #define dane 200000 typedef unsigned long long ull; typedef long long ll; ull max(ll x, ll y) { return x > y ? x : y; } ull p[dane+1]; ull c[dane+1]; ull wyn[dane+1]; ull s = 0; main() { int n, m; scanf("%d%d", &n, &m); for(int i=0;i<n;i++) { scanf("%llu", &c[i]); s += c[i]; } for(int i=0;i<m;i++) { scanf("%llu", &p[i]); } for(int i=0;i<m;i++) { ull res = 0; wyn[0] = max(0,c[0]-p[i]); for(int j=1;j<=n;j++) { wyn[j]=max(wyn[j-1]+p[i],c[j]-p[i]); } for(int j = 0; j < n; j++)res += wyn[j]; printf("%llu\n", res + n*p[i] - s); } } |