#include <iostream>
using namespace std;
int A[500001];
unsigned long long int H[500001];
int n, m,p_day=0;
void grow(int d)
{
for (int i = 0; i < n; i++)
H[i] += A[i] * d;
}
unsigned long long int cut(int b)
{
unsigned long long int sum = 0;
for (int i = 0; i < n; i++)
{
if (H[i] > b)
{
sum += H[i] - b;
H[i] = b;
}
}
return sum;
}
void read_data()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> A[i];
}
unsigned long long int read_day()
{
int d, h;
cin >> d >> h;
grow(d - p_day);
p_day = d;
return cut(h);
}
int main()
{
read_data();
for (int i = 0; i < m; i++)
cout << read_day() << 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 41 42 43 44 45 46 47 48 49 50 | #include <iostream> using namespace std; int A[500001]; unsigned long long int H[500001]; int n, m,p_day=0; void grow(int d) { for (int i = 0; i < n; i++) H[i] += A[i] * d; } unsigned long long int cut(int b) { unsigned long long int sum = 0; for (int i = 0; i < n; i++) { if (H[i] > b) { sum += H[i] - b; H[i] = b; } } return sum; } void read_data() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> A[i]; } unsigned long long int read_day() { int d, h; cin >> d >> h; grow(d - p_day); p_day = d; return cut(h); } int main() { read_data(); for (int i = 0; i < m; i++) cout << read_day() << endl; return 0; } |
English