#include <iostream> #include <vector> using namespace std; typedef unsigned long long ULL; int main(){ ULL n,m,tmp; cin >> n >> m; vector<ULL> growth(n); vector<ULL> field(n); for(int i=0; i<n; i++){ cin >> growth[i]; } ULL d,b; ULL prev_day=0; for(int k=0;k<m;k++){ cin >> d >> b; ULL res = 0; ULL days_grown = d - prev_day; for(ULL i=0; i<n; i++){ field[i] += days_grown*growth[i]; if (field[i] > b){ res += field[i] - b; field[i] = b; } } prev_day = d; cout << res << endl; } }
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 | #include <iostream> #include <vector> using namespace std; typedef unsigned long long ULL; int main(){ ULL n,m,tmp; cin >> n >> m; vector<ULL> growth(n); vector<ULL> field(n); for(int i=0; i<n; i++){ cin >> growth[i]; } ULL d,b; ULL prev_day=0; for(int k=0;k<m;k++){ cin >> d >> b; ULL res = 0; ULL days_grown = d - prev_day; for(ULL i=0; i<n; i++){ field[i] += days_grown*growth[i]; if (field[i] > b){ res += field[i] - b; field[i] = b; } } prev_day = d; cout << res << endl; } } |