# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
438949 | 2021-06-29T01:19:03 Z | jlozano254 | Distributing Candies (IOI21_candies) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* Time O(n2) Space O(n) */ /* Day Box 0 Box 1 Box 2 0 10 15 13 1 0 4 13 */ vector<int> dis_candies(int n, int q, vector<int> c, vector<int> l, vector<int> r, vector<int> v) { vector<int> candies(n); for (int i = 0; i <= n; ++i) { for (int j = l[i]; j <= r[i]; ++j) { if (v[i] < 0) { candies[j] = max(0, candies[j] + v[i]); } else { candies[j] = min(c[j], candies[j] + v[i]); } } } return candies; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin.precision(10); int aux, aux2, aux3; int n, q; vector<int> c, l, r, v; cin >> n; for (int i = 0; i < n; ++i) { cin >> aux; c.push_back(aux); } cin >> q; for (int i = 0; i < q; ++i) { cin >> aux >> aux2 >> aux3; l.push_back(aux); r.push_back(aux2); v.push_back(aux3); } auto candies = dis_candies(n, q, c, l, r, v); for (auto c : candies) cout << c << " "; //cout << endl; //cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << " seconds" << endl; return 0; }