Submission #1310490

#TimeUsernameProblemLanguageResultExecution timeMemory
1310490marcogambaroThe short shank; Redemption (BOI21_prison)C++20
0 / 100
49 ms5472 KiB
#include <bits/stdc++.h>
using namespace std;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define readv(v) do { for(auto &i: v) cin >> i; } while(0)
#define writev(v) do { for(auto i: v) cout << i << " "; } while(0)
#define _ << " " <<
#define ll long long
#define u64 unsigned long long
#ifndef MARCO
bool dbg = 0;
#define info(str, ...)
#define infon(str, ...)
#else
bool dbg = 1;
#define info(str, ...) do { fprintf(stderr, "\033[31m" str "\033[0m", ##__VA_ARGS__); } while(0)
#define infon(str, ...) do { fprintf(stderr, "\033[31m" str "\033[0m\n", ##__VA_ARGS__); } while(0)
#endif
constexpr int LOG = 30;



signed main(){	
	ios::sync_with_stdio(false);
	cin.tie(nullptr);   
    
    int N, d, T; cin >> N >> d >> T;
	vector<int> V(N);
	readv(V);
    
    stack<int> rebels;
	vector<int> pw(N+1);
	pw[N] = -1;

	int bst = N;
	int reb = N;

	for(int i=0; i<N; i++) {
		rebels.push(i);

		while(!rebels.empty() && i - rebels.top() + V[rebels.top()] > T) {
			if(pw[rebels.top()] > pw[bst]) bst = rebels.top();
			rebels.pop();
		}
		if(rebels.empty()) {
			reb--, bst = N;
			continue;
		}

		if(pw[bst] > pw[rebels.top()] && bst > rebels.top()) 
			pw[bst]++;
		else		pw[rebels.top()]++;
	}

	infon("pw ...");
	for(int i: pw) info("%d ", i); infon("");

	sort(rall(pw));
	for(int i=0; i<d; i++) reb -= pw[i]-1;

	cout << reb << "\n";
}




#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...
#Verdict Execution timeMemoryGrader output
Fetching results...