#include<stdio.h> #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); vector<int> r(n); for(int i=0;i<n;i++) { scanf("%d",&r[i]); } vector<unsigned long long int> v(n,0); unsigned long long int t,s,q=0,qq=1000000000000,l=0,w=0,d=0; for(int j=0;j<m;j++) { scanf("%Ld%Ld",&q,&w); d=q-l; l=q; s=0; for(int i=0;i<n;i++) { t=min(qq,v[i]+d*r[i]); s+=(t>w)?t-w:0; v[i]=(t>w)?w:t; //printf("%Ld %Ld ",s,v[i]); } printf("%Ld\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 35 36 | #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); vector<int> r(n); for(int i=0;i<n;i++) { scanf("%d",&r[i]); } vector<unsigned long long int> v(n,0); unsigned long long int t,s,q=0,qq=1000000000000,l=0,w=0,d=0; for(int j=0;j<m;j++) { scanf("%Ld%Ld",&q,&w); d=q-l; l=q; s=0; for(int i=0;i<n;i++) { t=min(qq,v[i]+d*r[i]); s+=(t>w)?t-w:0; v[i]=(t>w)?w:t; //printf("%Ld %Ld ",s,v[i]); } printf("%Ld\n",s); } return 0; } |