#include <iostream> #include <vector> using namespace std; int main() { int k , p; cin>>k>>p; vector<long long> client; vector<long long> piec; long long temp; for(int i = 0 ; i < k ; i ++) { cin>>temp; client.push_back(temp); } for(int i = 0 ; i < p ; i ++) { cin>>temp; piec.push_back(temp); } for(int ddd = 0 ; ddd < p ; ddd++) { long long time = piec[ddd]; long long prev = 0; long long ans = 0; for(int i = 0 ; i < k ; i ++) { long long st = max(prev , client[i]-time); ans += st+time - client[i]; prev = st + time; } cout<<ans<<endl; } }
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 | #include <iostream> #include <vector> using namespace std; int main() { int k , p; cin>>k>>p; vector<long long> client; vector<long long> piec; long long temp; for(int i = 0 ; i < k ; i ++) { cin>>temp; client.push_back(temp); } for(int i = 0 ; i < p ; i ++) { cin>>temp; piec.push_back(temp); } for(int ddd = 0 ; ddd < p ; ddd++) { long long time = piec[ddd]; long long prev = 0; long long ans = 0; for(int i = 0 ; i < k ; i ++) { long long st = max(prev , client[i]-time); ans += st+time - client[i]; prev = st + time; } cout<<ans<<endl; } } |