#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #define MAXN 500000 using namespace std; typedef unsigned long long ull; int A[MAXN]; ull B[MAXN]; int main() { int n, m, i; ull a, d, al; ull wynik; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &A[i]); B[i] = 0; } al = 0; while (m--) { wynik = 0; scanf("%llu%llu", &a, &d); for (i = 0; i < n; i++) { B[i] += (A[i] * (a- al)); if (B[i] > d) { wynik += (B[i] - d); B[i] = d; } } al = a; printf("%llu\n", wynik); } 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 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #define MAXN 500000 using namespace std; typedef unsigned long long ull; int A[MAXN]; ull B[MAXN]; int main() { int n, m, i; ull a, d, al; ull wynik; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &A[i]); B[i] = 0; } al = 0; while (m--) { wynik = 0; scanf("%llu%llu", &a, &d); for (i = 0; i < n; i++) { B[i] += (A[i] * (a- al)); if (B[i] > d) { wynik += (B[i] - d); B[i] = d; } } al = a; printf("%llu\n", wynik); } return 0; } |