Submission #1092983

#TimeUsernameProblemLanguageResultExecution timeMemory
1092983huyngoDistributing Candies (IOI21_candies)C++17
11 / 100
336 ms13884 KiB
#include "candies.h" #include<bits/stdc++.h> using namespace std; std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int n = c.size(), q = v.size(); if (n <= 2000) { vector<int> ans(n); for (int i = 0; i < q; ++i) { for (int j = l[i]; j <= r[i]; ++j) { if (v[i] > 0) ans[j] = min(c[j], ans[j] + v[i]); else ans[j] = max(0, ans[j] + v[i]); } } return ans; } if (*min_element(v.begin(), v.end()) > 0) { vector<int64_t> s(n + 1); vector<int> ans(n); for (int i = 0; i < q; ++i) { s[l[i]] += v[i]; s[r[i] + 1] -= v[i]; } for (int i = 0; i < n; ++i) { s[i] += (i ? s[i - 1] : 0); ans[i] = (s[i] <= c[i] ? s[i] : c[i]); } return ans; } int cur = 0; for (int i = 0; i < q; ++i) { if (v[i] > 0) cur = min(c[0], cur + v[i]); else cur = max(0, cur + v[i]); } return vector<int>(n, cur); }
#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...