# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
698070 | Tien_Noob | The short shank; Redemption (BOI21_prison) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e6;
int n, T, cnt[N + 1], deg[N + 1], a[N + 1], d;
struct FenwickTree
{
int tree[N + 1];
void add(int pos, int val)
{
pos = min(pos, val);
for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
{
tree[pos] = val;
}
}
int get(int pos)
{
int ret = 0;
for (; pos <= n; pos |= pos + 1)
{
ret = max(ret, tree[pos]);
}
return ret;
}
} tree;
int res;
void read()
{
cin >> n >> d >> T;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
if (a[i] > T)
{
int pre = tree.get(i);
if (pre == 0)
{
++res;
}
else
{
--cnt[deg[pre]];
++deg[pre];
++cnt[deg[pre]];
}
}
else
{
tree.add(T + i - a[i], i);
}
}
}
void solve()
{
for (int i = n; i >= 1; -- i)
{
while(cnt[i] > 0 && d > 0)
{
res += i;
--cnt[i];
--d;
}
}
cout << n - res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |