Submission #617185

#TimeUsernameProblemLanguageResultExecution timeMemory
617185happypotatoDistributing Candies (IOI21_candies)C++17
11 / 100
117 ms14024 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int n = c.size(), q = l.size(); if (n <= 2000 && q <= 2000) { vector<int> a(n, 0); for (int i = 0; i < q; i++) { for (int j = l[i]; j <= r[i]; j++) { a[j] += v[i]; a[j] = min(a[j], c[j]); a[j] = max(a[j], 0); } } return a; } bool allpos = true; for (int &x : v) { allpos &= (x > 0); } if (allpos) { ll int diff[n] = {0}; for (int i = 0; i < q; i++) { diff[l[i]] += v[i]; if (r[i] != n - 1) diff[r[i] + 1] -= v[i]; } vector<int> ans; ll int ps = 0; for (int i = 0; i < n; i++) { ps += diff[i]; ans.pb((ps < c[i] ? ps : c[i])); } return ans; } return {}; }
#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...