Submission #440515

#TimeUsernameProblemLanguageResultExecution timeMemory
440515MetalPowerDistributing Candies (IOI21_candies)C++17
11 / 100
127 ms8932 KiB
#include <bits/stdc++.h> using namespace std; #include "candies.h" #define ll long long vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){ int N = c.size(), Q = v.size(); vector<int> ans(N, 0); if(N <= 2000 && Q <= 2000){ for(int i = 0; i < Q; i++){ for(int j = l[i]; j <= r[i]; j++){ if(v[i] < 0) ans[j] = max(0, ans[j] + v[i]); else if(v[i] > 0) ans[j] = min(c[j], ans[j] + v[i]); } } }else{ vector<ll> 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++){ if(pref[i] > (ll) c[i]) ans[i] = c[i]; else ans[i] = pref[i]; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...