#include <iostream> #include <vector> #include <map> using namespace std; uint64_t solve(const uint64_t d, const vector<uint64_t>& t) { uint64_t T{}, R{}; for (size_t i = 0; i < t.size(); ++i) { if (T + d < t[i]) { T = t[i] - d; } R += d - (t[i] - T); T += d; } return R; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<uint64_t> t(n); for (size_t i = 0; i < n; cin >> t[i++]); map<int, uint64_t> r; for (int i = 0; i < m; ++i) { int d; cin >> d; if (r.count(d) == 0) r[d] = solve(d, t); cout << r[d] << '\n'; } 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 | #include <iostream> #include <vector> #include <map> using namespace std; uint64_t solve(const uint64_t d, const vector<uint64_t>& t) { uint64_t T{}, R{}; for (size_t i = 0; i < t.size(); ++i) { if (T + d < t[i]) { T = t[i] - d; } R += d - (t[i] - T); T += d; } return R; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<uint64_t> t(n); for (size_t i = 0; i < n; cin >> t[i++]); map<int, uint64_t> r; for (int i = 0; i < m; ++i) { int d; cin >> d; if (r.count(d) == 0) r[d] = solve(d, t); cout << r[d] << '\n'; } return 0; } |