#include <stdio.h> #define MAX 200001 long long int wyn[MAX] = {}; int main(){ int i ,n, m, p[MAX]; long long int k[MAX], d[MAX], pop, temp; scanf("%d %d", &n, &m); for(i = 0; i < n; ++i){ scanf("%lld", &k[i]); } for(i = 0; i < m; ++i){ scanf("%d", &p[i]); } d[0] = k[0]; for(i = 1; i < n; ++i){ d[i] = k[i] - k[i-1]; } for(int j = 0; j < m; ++j){ pop = 0; for (i = 0; i < n; ++i){ temp = d[i] - pop; if(p[j] > temp) { wyn[j] += p[j] - temp; pop = p[j] - temp; }else{ pop = 0; } } } for(i = 0; i < m; ++i){ printf("%lld\n", wyn[i]); } 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 | #include <stdio.h> #define MAX 200001 long long int wyn[MAX] = {}; int main(){ int i ,n, m, p[MAX]; long long int k[MAX], d[MAX], pop, temp; scanf("%d %d", &n, &m); for(i = 0; i < n; ++i){ scanf("%lld", &k[i]); } for(i = 0; i < m; ++i){ scanf("%d", &p[i]); } d[0] = k[0]; for(i = 1; i < n; ++i){ d[i] = k[i] - k[i-1]; } for(int j = 0; j < m; ++j){ pop = 0; for (i = 0; i < n; ++i){ temp = d[i] - pop; if(p[j] > temp) { wyn[j] += p[j] - temp; pop = p[j] - temp; }else{ pop = 0; } } } for(i = 0; i < m; ++i){ printf("%lld\n", wyn[i]); } return 0; } |