#include<cstdio> int n, m; long long * t; long long * d; void input() { scanf("%d %d", &n, &m); t = new long long[n]; d = new long long[m]; for (int i = 0; i < n; i++) { scanf("%lld", t + i); } for (int i = 0; i < m; i++) { scanf("%lld", d + i); } } void brute(long long waiting_time) { long long result = 0; long long current_time = 0; for (int i = 0; i < n; i++) { long long next_time = current_time + waiting_time; if (next_time > t[i]) { result += (next_time - t[i]); current_time = next_time; } else { current_time = t[i]; } } printf("%lld\n", result); } void brute() { for (int i = 0; i < m; i++) { brute(d[i]); } } int main(int argc, char ** argv) { input(); brute(); 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 | #include<cstdio> int n, m; long long * t; long long * d; void input() { scanf("%d %d", &n, &m); t = new long long[n]; d = new long long[m]; for (int i = 0; i < n; i++) { scanf("%lld", t + i); } for (int i = 0; i < m; i++) { scanf("%lld", d + i); } } void brute(long long waiting_time) { long long result = 0; long long current_time = 0; for (int i = 0; i < n; i++) { long long next_time = current_time + waiting_time; if (next_time > t[i]) { result += (next_time - t[i]); current_time = next_time; } else { current_time = t[i]; } } printf("%lld\n", result); } void brute() { for (int i = 0; i < m; i++) { brute(d[i]); } } int main(int argc, char ** argv) { input(); brute(); return 0; } |