//============================================================================
// Name : Siano.cpp
// Author : Tytus Bierwiaczonek
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <stdint.h>
using namespace std;
const uint64_t nMax = 500000;
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
uint64_t n, m, i, j, d, dLast = 0, b;
uint64_t result = 0;
uint64_t grassTypes[nMax];
uint64_t grassHeight[nMax];
cin >> n >> m;
for (i = 0; i < n; ++i)
{
grassHeight[i] = 0;
cin >> grassTypes[i];
}
for (j = 0; j < m; ++j)
{
cin >> d >> b;
for (i = 0; i < n; ++i)
{
grassHeight[i] += (d - dLast) * grassTypes[i];
if (grassHeight[i] > b)
{
result += grassHeight[i] - b;
}
grassHeight[i] = min(b, grassHeight[i]);
}
cout << result << endl;
result = 0;
dLast = d;
}
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 | //============================================================================ // Name : Siano.cpp // Author : Tytus Bierwiaczonek // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdint.h> using namespace std; const uint64_t nMax = 500000; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); uint64_t n, m, i, j, d, dLast = 0, b; uint64_t result = 0; uint64_t grassTypes[nMax]; uint64_t grassHeight[nMax]; cin >> n >> m; for (i = 0; i < n; ++i) { grassHeight[i] = 0; cin >> grassTypes[i]; } for (j = 0; j < m; ++j) { cin >> d >> b; for (i = 0; i < n; ++i) { grassHeight[i] += (d - dLast) * grassTypes[i]; if (grassHeight[i] > b) { result += grassHeight[i] - b; } grassHeight[i] = min(b, grassHeight[i]); } cout << result << endl; result = 0; dLast = d; } return 0; } |
English