Submission #1067381

#TimeUsernameProblemLanguageResultExecution timeMemory
1067381golfDistributing Candies (IOI21_candies)C++17
3 / 100
65 ms10580 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(); int q = v.size(); if (q <= 2000 && n <= 2000) { vector<int> s(n); for (int i = 0; i < q; i++) { for (int j = l[i]; j <= r[i]; j++) { s[j] = max(min(s[j] + v[i], c[j]), 0); } } return s; } bool pos = true; for (int i = 0; i < n; i++) { if (c[i] < 0) { pos = false; break; } } if (pos) { // difference array vector<long long> d(n + 1); for (int i = 0; i < q; i++) { d[l[i]] += v[i]; d[r[i] + 1] -= v[i]; } vector<long long> s(n); s[0] = d[0]; for (int i = 1; i < n; i++) { s[i] = min(s[i - 1] + d[i], (long long)c[i]); } vector<int> res(n); for (int i = 0; i < n; i++) { res[i] = s[i]; } return res; } vector<int> s(n, 0); return s; }
#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...