#ifdef _MSC_VER
#ifndef __GNUC__
#pragma warning(disable: 4996)
#endif
#define main main0
#endif
#include <iostream>
using namespace std;
static const int Max = 500000;
long long speed[Max];
long long height[Max];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m;
long long previous, current, trimming, result = 0;
cin >> n >> m;
for(int i = 0; i < n; ++i)
cin >> speed[i];
cin >> current >> trimming;
previous = current;
for(int j = 0; j < n; ++j) {
height[j] = speed[j] * previous;
if(height[j] > trimming) {
result += height[j] - trimming;
height[j] = trimming;
}
}
cout << result << '\n';
for(int i = 1; i < m; ++i) {/*/
for(int i = 0; i < m; ++i) {//*/
result = 0;
cin >> current >> trimming;
previous = current - previous;
for(int j = 0; j < n; ++j) {
height[j] += speed[j] * previous;
if(height[j] > trimming) {
result += height[j] - trimming;
height[j] = trimming;
}
}
previous = current;
cout << result << '\n';
}
cout.flush();
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 41 42 43 44 45 46 47 48 49 50 51 52 53 | #ifdef _MSC_VER #ifndef __GNUC__ #pragma warning(disable: 4996) #endif #define main main0 #endif #include <iostream> using namespace std; static const int Max = 500000; long long speed[Max]; long long height[Max]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m; long long previous, current, trimming, result = 0; cin >> n >> m; for(int i = 0; i < n; ++i) cin >> speed[i]; cin >> current >> trimming; previous = current; for(int j = 0; j < n; ++j) { height[j] = speed[j] * previous; if(height[j] > trimming) { result += height[j] - trimming; height[j] = trimming; } } cout << result << '\n'; for(int i = 1; i < m; ++i) {/*/ for(int i = 0; i < m; ++i) {//*/ result = 0; cin >> current >> trimming; previous = current - previous; for(int j = 0; j < n; ++j) { height[j] += speed[j] * previous; if(height[j] > trimming) { result += height[j] - trimming; height[j] = trimming; } } previous = current; cout << result << '\n'; } cout.flush(); return 0; } |
English