#include <iostream> #include <vector> using namespace std; int main() { uint64_t day, nextDay, b, w; uint32_t n, m; ios_base::sync_with_stdio(0); cin>>n; cin>>m; vector<uint32_t> a(n); vector<uint32_t> h(n); for(uint32_t i = 0; i < n; ++i) { cin>>a[i]; } nextDay = 0; for(uint32_t i = 0; i < m; ++i) { w = 0; day = nextDay; cin>>nextDay; cin>>b; for(uint32_t j = 0; j < n; ++j) { h[j] += a[j] * (nextDay - day); if(h[j] > b) { w += h[j] - b; h[j] = b; } } cout<<w<<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 37 38 39 40 | #include <iostream> #include <vector> using namespace std; int main() { uint64_t day, nextDay, b, w; uint32_t n, m; ios_base::sync_with_stdio(0); cin>>n; cin>>m; vector<uint32_t> a(n); vector<uint32_t> h(n); for(uint32_t i = 0; i < n; ++i) { cin>>a[i]; } nextDay = 0; for(uint32_t i = 0; i < m; ++i) { w = 0; day = nextDay; cin>>nextDay; cin>>b; for(uint32_t j = 0; j < n; ++j) { h[j] += a[j] * (nextDay - day); if(h[j] > b) { w += h[j] - b; h[j] = b; } } cout<<w<<endl; } return 0; } |