#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int lp, lk; long long min_delay; long long cook_time; long long arrivals[200000]; long long begin_cook_time; cin >> lk >> lp; for ( int i = 0; i < lk; i++ ) cin >> arrivals[i]; while (lp--) { min_delay = 0; begin_cook_time = 0; cin >> cook_time; for ( int i = 0; i < lk; i++ ) { if ( begin_cook_time + cook_time <= arrivals[i] ) begin_cook_time = arrivals[i]; else { begin_cook_time += cook_time; min_delay += begin_cook_time - arrivals[i]; } } cout << min_delay << endl; } 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 | #include <iostream> using namespace std; int main(int argc, const char * argv[]) { int lp, lk; long long min_delay; long long cook_time; long long arrivals[200000]; long long begin_cook_time; cin >> lk >> lp; for ( int i = 0; i < lk; i++ ) cin >> arrivals[i]; while (lp--) { min_delay = 0; begin_cook_time = 0; cin >> cook_time; for ( int i = 0; i < lk; i++ ) { if ( begin_cook_time + cook_time <= arrivals[i] ) begin_cook_time = arrivals[i]; else { begin_cook_time += cook_time; min_delay += begin_cook_time - arrivals[i]; } } cout << min_delay << endl; } return 0; } |