Submission #560690

#TimeUsernameProblemLanguageResultExecution timeMemory
560690AlperenTDistributing Candies (IOI21_candies)C++17
3 / 100
115 ms10704 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int n = c.size(), q = l.size(); vector<int> ans(n); bool sub2flag = true; for(auto x : v) if(x < 0) sub2flag = false; if(n <= 2000 && q <= 2000){ // subtask 1 vector<int> arr(n); for(int i = 0; i < q; i++){ for(int j = l[i]; j <= r[i]; j++){ arr[j] += v[i]; arr[j] = max(0, arr[j]); arr[j] = min(c[j], arr[j]); } } ans = arr; } else if(sub2flag){ // subtask 2 vector<int> prefix(n + 1); for(int i = 0; i < q; i++){ prefix[l[i]] += v[i]; prefix[r[i] + 1] -= v[i]; } for(int i = 1; i < n; i++) prefix[i] += prefix[i - 1]; for(int i = 0; i < n; i++) ans[i] = min(prefix[i], c[i]); } else{ // cry till I die } 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...