#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long int LLI; LLI key[500005]; LLI tab[500005]; int main(){ ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> key[i]; } LLI curD = 0LL; for(int i = 0; i < m; i++){ LLI d, b; cin >> d >> b; LLI result=0; for(int j = 0; j < n; j++){ tab[j] += key[j]*(d-curD); if(tab[j] > b){ result += tab[j]-b; tab[j]=b; } } curD=d; cout << result << "\n"; } }
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 <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long int LLI; LLI key[500005]; LLI tab[500005]; int main(){ ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> key[i]; } LLI curD = 0LL; for(int i = 0; i < m; i++){ LLI d, b; cin >> d >> b; LLI result=0; for(int j = 0; j < n; j++){ tab[j] += key[j]*(d-curD); if(tab[j] > b){ result += tab[j]-b; tab[j]=b; } } curD=d; cout << result << "\n"; } } |