#include <bits/stdc++.h>
#include <weirdtree.h>
using namespace std;
typedef long long ll;
int n;
ll arr[300001];
void initialise (int N, int q, int h[]) {
n = N;
for (int i = 1; i <= n; i++) {
arr[i] = h[i];
}
}
void cut (int l, int r, int k) {
vector <pair <ll, ll>> dd;
ll sum = 0;
for (int i = l; i <= r; i++) {
if (arr[i] < 0) return;
dd.push_back({arr[i], i});
sum += arr[i];
}
if (sum <= k) {
for (int i = l; i <= r; i++) arr[i] = 0;
return;
}
sort(dd.begin(), dd.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) {
return a.first == b.first ? a.second < b.second : a.first > b.first;
});
dd.push_back({0, (ll)1e9});
for (int i = 1; i < (int)dd.size(); i++) {
if (dd[i].first == dd[i - 1].first) continue;
ll t = (dd[i - 1].first - dd[i].first) * i;
if (t <= k) {
k -= t;
continue;
}
ll y = k / i;
for (int j = 0; j < i; j++) arr[dd[j].second] = dd[i - 1].first - y;
k %= i;
sort(dd.begin(), dd.begin() + i, [] (pair <ll, ll> &a, pair <ll, ll> &b) {
return a.second < b.second;
});
for (int j = 0; j < k; j++) arr[dd[j].second]--;
return;
}
}
void magic (int i, int x) {
}
ll inspect (int l, int r) {
ll sum = 0;
for (int i = l; i <= r; i++) {
if (arr[i] < 0) return 0;
sum += arr[i];
}
return sum;
}/*
int main () {
int n, q;
cin >> n >> q;
int arr2[n + 1] = {};
for (int i = 1; i <= n; i++) {
cin >> arr2[i];
}
initialise(n, q, arr2);
while (q--) {
int k;
cin >> k;
if (k == 1) {
int l, r, x;
cin >> l >> r >> x;
cut(l, r, x);
} else {
int l, r;
cin >> l >> r;
cout << inspect(l, r) << '\n';
}
}
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
352 KB |
Output is correct |
2 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
352 KB |
Output is correct |
2 |
Correct |
8 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2007 ms |
20536 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
17844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |