//#include <iostream> #include <cstdio> //using namespace std; typedef long long ll; int main(void) { // std::ios_base::sync_with_stdio(false); const int vSize = 200000; ll vn[vSize]; ll vm[vSize]; ll n, m, t, waitingTime, currentTime; scanf("%lld %lld", &n, &m); // std::cin >> n >> m; for(int i = 0; i < n; i++) scanf("%lld", &vn[i]); for(int i = 0; i < m; i++) scanf("%lld", &vm[i]); for(int j = 0; j < m; j++) { waitingTime = 0; currentTime = 0; t = vm[j]; for(int i = 0; i < n; i++) { if(currentTime + t <= vn[i]) currentTime = vn[i]; else { currentTime = currentTime + t; waitingTime += currentTime - vn[i]; } } printf("%lld\n", waitingTime); } 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 | //#include <iostream> #include <cstdio> //using namespace std; typedef long long ll; int main(void) { // std::ios_base::sync_with_stdio(false); const int vSize = 200000; ll vn[vSize]; ll vm[vSize]; ll n, m, t, waitingTime, currentTime; scanf("%lld %lld", &n, &m); // std::cin >> n >> m; for(int i = 0; i < n; i++) scanf("%lld", &vn[i]); for(int i = 0; i < m; i++) scanf("%lld", &vm[i]); for(int j = 0; j < m; j++) { waitingTime = 0; currentTime = 0; t = vm[j]; for(int i = 0; i < n; i++) { if(currentTime + t <= vn[i]) currentTime = vn[i]; else { currentTime = currentTime + t; waitingTime += currentTime - vn[i]; } } printf("%lld\n", waitingTime); } return 0; } |