#include<stdio.h> long long int maximum(long long int a, long long int b) { return a > b ? a : b; } int main() { long long int start, end, wait, sum, oven; long long int customerCount, ovenCount; long long int i,j; scanf("%lld %lld", &customerCount, &ovenCount); long long int customers[customerCount]; for(i = 0; i < customerCount; i++) { scanf("%lld", &customers[i]); } for(j = 0; j < ovenCount; j++) { scanf("%lld", &oven); sum = 0; start = 0; end = 0; for(i = 0; i < customerCount; i++) { start = maximum(0, maximum(end, customers[i] - oven)); end = start + oven; wait = end - customers[i]; sum += wait; } printf("%lld\n", sum); } }
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 | #include<stdio.h> long long int maximum(long long int a, long long int b) { return a > b ? a : b; } int main() { long long int start, end, wait, sum, oven; long long int customerCount, ovenCount; long long int i,j; scanf("%lld %lld", &customerCount, &ovenCount); long long int customers[customerCount]; for(i = 0; i < customerCount; i++) { scanf("%lld", &customers[i]); } for(j = 0; j < ovenCount; j++) { scanf("%lld", &oven); sum = 0; start = 0; end = 0; for(i = 0; i < customerCount; i++) { start = maximum(0, maximum(end, customers[i] - oven)); end = start + oven; wait = end - customers[i]; sum += wait; } printf("%lld\n", sum); } } |