#include <iostream> #define REP(x,n) for(int x=0;x<(n);++x) using namespace std; int n,m,piekarnik; typedef long long LL; const int MAX_N = 200001; LL klienci[MAX_N]; int main() { cin>>n>>m; REP(x,n) cin>>klienci[x]; REP(x,m) { cin>>piekarnik; LL prev=0; LL wyn=0; REP(y,n) { if(prev+piekarnik > klienci[y]) { wyn += prev+piekarnik-klienci[y]; prev += piekarnik; } else { prev = klienci[y]; } } cout<<wyn<<endl; } 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 <iostream> #define REP(x,n) for(int x=0;x<(n);++x) using namespace std; int n,m,piekarnik; typedef long long LL; const int MAX_N = 200001; LL klienci[MAX_N]; int main() { cin>>n>>m; REP(x,n) cin>>klienci[x]; REP(x,m) { cin>>piekarnik; LL prev=0; LL wyn=0; REP(y,n) { if(prev+piekarnik > klienci[y]) { wyn += prev+piekarnik-klienci[y]; prev += piekarnik; } else { prev = klienci[y]; } } cout<<wyn<<endl; } return 0; } |