# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1064208 | 2024-08-18T10:25:21 Z | glupan | Distributing Candies (IOI21_candies) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int ok = 1; for(auto u : v) if(u < 0) ok=0; int n = c.size(), q = l.size(); if(ok) { vector<int>s(n); vector<long long> pref(n+1,0); for(int i=0; i<q; i++) { pref[l[i]] += v[i]; pref[r[i]+1] -= v[i]; } for(int i=1; i<=n; i++) pref[i]+=pref[i-1]; for(int i=0; i<n; i++) s[i] = min((long long)c[i],pref[i]); return s; } else { vector<int>s(n,0); for(int i=0; i<q; i++) { for(int j=l[i], j<=r[i]; j++) { if(v[i] > 0) s[i] = min(c[i], s[i] + v[i]); else s[i] = max(0, s[i] + v[i]); } } return s; } }