#include <stdio.h>
using namespace std;
int main()
{
int n, m;
scanf("%d %d", & n, & m );
int ** squares = new int * [n];
for (int i = 0; i < n; i++)
{
squares[i] = new int[2];
scanf("%d", & squares[i][0]);
}
int ** cutting = new int * [m];
int lday = 0;
for (int i = 0; i < m; i++)
{
cutting[i] = new int[2];
int day = 0;
int centimeters = 0;
scanf("%d %d", & day, & centimeters);
int days_passed = day - lday;
lday = day;
cutting[i][0] = days_passed;
cutting[i][1] = centimeters;
}
for (int i = 0; i < m; i++)
{
int all_cut = 0;
int days_passed = cutting[i][0];
int centimeters = cutting[i][1];
for (int j = 0; j < n; j++)
{
squares[j][1] += days_passed * squares[j][0];
if (centimeters < squares[j][1])
{
all_cut += squares[j][1] - centimeters;
squares[j][1] = centimeters;
}
}
printf("%d\n", all_cut);
}
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 54 55 56 | #include <stdio.h> using namespace std; int main() { int n, m; scanf("%d %d", & n, & m ); int ** squares = new int * [n]; for (int i = 0; i < n; i++) { squares[i] = new int[2]; scanf("%d", & squares[i][0]); } int ** cutting = new int * [m]; int lday = 0; for (int i = 0; i < m; i++) { cutting[i] = new int[2]; int day = 0; int centimeters = 0; scanf("%d %d", & day, & centimeters); int days_passed = day - lday; lday = day; cutting[i][0] = days_passed; cutting[i][1] = centimeters; } for (int i = 0; i < m; i++) { int all_cut = 0; int days_passed = cutting[i][0]; int centimeters = cutting[i][1]; for (int j = 0; j < n; j++) { squares[j][1] += days_passed * squares[j][0]; if (centimeters < squares[j][1]) { all_cut += squares[j][1] - centimeters; squares[j][1] = centimeters; } } printf("%d\n", all_cut); } return 0; } |
polski