#include <stdio.h> #include <stdlib.h> int n, m; long long int temp; long long int prev_end; long long int avg[1000000]; int time[1000000]; long long int arrive[1000000]; int main() { scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) { scanf("%lld", &arrive[i]); } for(int i = 0; i < m; i++) { scanf("%d", &time[i]); } for(int x = 0; x < m; x++) { if (avg[time[x]] != 0){ printf("%lld\n", avg[time[x]]); continue; } prev_end = 0; for (int i = 0; i < n; i++) { prev_end += time[x]; if (prev_end > arrive[i]) { avg[time[x]] += (prev_end - arrive[i]); } else { prev_end = arrive[i]; } } printf("%lld\n", avg[time[x]]); } 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> #include <stdlib.h> int n, m; long long int temp; long long int prev_end; long long int avg[1000000]; int time[1000000]; long long int arrive[1000000]; int main() { scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) { scanf("%lld", &arrive[i]); } for(int i = 0; i < m; i++) { scanf("%d", &time[i]); } for(int x = 0; x < m; x++) { if (avg[time[x]] != 0){ printf("%lld\n", avg[time[x]]); continue; } prev_end = 0; for (int i = 0; i < n; i++) { prev_end += time[x]; if (prev_end > arrive[i]) { avg[time[x]] += (prev_end - arrive[i]); } else { prev_end = arrive[i]; } } printf("%lld\n", avg[time[x]]); } return 0; } |