#include <stdio.h> #include <vector> #include <algorithm> unsigned long long get_delay(unsigned long long visitors[], int n, int d) { unsigned long long delay = 0; unsigned long long position = 0; for (int i = 0; i < n; i++) { position = std::max(position + d, visitors[i]); delay += position == visitors[i] ? 0 : position - visitors[i]; } return delay; } int main() { int n, m; unsigned long long visitors[200000]; scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) { scanf("%lld", &visitors[i]); } for(int i = 0; i < m; i++) { int d; scanf("%d", &d); printf("%lld\n", get_delay(visitors, n, 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 | #include <stdio.h> #include <vector> #include <algorithm> unsigned long long get_delay(unsigned long long visitors[], int n, int d) { unsigned long long delay = 0; unsigned long long position = 0; for (int i = 0; i < n; i++) { position = std::max(position + d, visitors[i]); delay += position == visitors[i] ? 0 : position - visitors[i]; } return delay; } int main() { int n, m; unsigned long long visitors[200000]; scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) { scanf("%lld", &visitors[i]); } for(int i = 0; i < m; i++) { int d; scanf("%d", &d); printf("%lld\n", get_delay(visitors, n, d)); } return 0; }; |