#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; const int SZ=200200; ll T[SZ]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;++i) scanf("%lld",&T[i]); int d; ll pw,p; ll S; for(int i=0;i<m;++i) { scanf("%d",&d); pw=S=0L; for(int j=0;j<n;++j) { p=T[j]-d; if(p<pw)p=pw; pw=p+d; S+=pw-T[j]; } printf("%lld\n",S); } return 0; }
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 | #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; const int SZ=200200; ll T[SZ]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;++i) scanf("%lld",&T[i]); int d; ll pw,p; ll S; for(int i=0;i<m;++i) { scanf("%d",&d); pw=S=0L; for(int j=0;j<n;++j) { p=T[j]-d; if(p<pw)p=pw; pw=p+d; S+=pw-T[j]; } printf("%lld\n",S); } return 0; } |