#include <iostream> #include <vector> #include <algorithm> using namespace std; template <class T> void read(T &v, int n) { for (auto i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } } int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<unsigned long long> t; t.reserve(n+1); t.push_back(0); read(t, n); vector<int> d; d.reserve(m); read(d, m); for (auto i = 0; i < m; i++) { unsigned long long p = d[i]; unsigned long long s = 0; unsigned long long sum = 0; for (auto j = 1; j <= n; j++) { s += p; if (s < t[j]) s = t[j]; sum += s - t[j]; } cout << sum << 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 50 | #include <iostream> #include <vector> #include <algorithm> using namespace std; template <class T> void read(T &v, int n) { for (auto i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } } int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<unsigned long long> t; t.reserve(n+1); t.push_back(0); read(t, n); vector<int> d; d.reserve(m); read(d, m); for (auto i = 0; i < m; i++) { unsigned long long p = d[i]; unsigned long long s = 0; unsigned long long sum = 0; for (auto j = 1; j <= n; j++) { s += p; if (s < t[j]) s = t[j]; sum += s - t[j]; } cout << sum << endl; } return 0; } |