#define dbg if(0)
#include <bits/stdc++.h>
using namespace std;
//typedef unsigned long long ull;
typedef long long ull;
vector <ull> T;
vector <ull> D;
int main(){
int n, m;
ull tmp;
cin >> n >> m;
for(int i = 0; i < n; ++i){
cin >> tmp;
T.push_back(tmp);
}
for(int i = 0; i < m; ++i){
cin >> tmp;
D.push_back(tmp);
}
ull pos = 0; // current position
ull penalty = 0;
unsigned int t_id = 0;
for(ull d : D){
t_id = 0;
penalty = 0;
pos = max(T[t_id]-d, 0ll);
dbg cout << "D: " << d << " INITIAL POSITION: " << pos << endl;
while(t_id < T.size()){
pos += d;
penalty += pos - T[t_id];
++t_id;
pos = max(pos, T[t_id]-d);
dbg cout << "COVERING T_ID: " << t_id << " T[t_id]: " << T[t_id] << " POS after: " << pos << " PENALTY after: " << penalty << endl;
}
cout << penalty << 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #define dbg if(0) #include <bits/stdc++.h> using namespace std; //typedef unsigned long long ull; typedef long long ull; vector <ull> T; vector <ull> D; int main(){ int n, m; ull tmp; cin >> n >> m; for(int i = 0; i < n; ++i){ cin >> tmp; T.push_back(tmp); } for(int i = 0; i < m; ++i){ cin >> tmp; D.push_back(tmp); } ull pos = 0; // current position ull penalty = 0; unsigned int t_id = 0; for(ull d : D){ t_id = 0; penalty = 0; pos = max(T[t_id]-d, 0ll); dbg cout << "D: " << d << " INITIAL POSITION: " << pos << endl; while(t_id < T.size()){ pos += d; penalty += pos - T[t_id]; ++t_id; pos = max(pos, T[t_id]-d); dbg cout << "COVERING T_ID: " << t_id << " T[t_id]: " << T[t_id] << " POS after: " << pos << " PENALTY after: " << penalty << endl; } cout << penalty << endl; } return 0; } |
English