이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 550;
int n, d, T, t[maxn], r[maxn], qtd[maxn], trT[4*maxn];
set<pair<int,int>> st;
void buildT(int no, int l, int r) {
trT[no] = inf;
if(l != r) {
int f1=2*no;
int f2=2*no+1;
int mid = (l+r)>>1;
buildT(f1,l,mid);
buildT(f2,mid+1,r);
}
}
void attT(int no, int l, int r, int pos, int val) {
if(l > pos || r < pos) return;
if(l == r) {
trT[no] = val;
return;
}
int f1=2*no;
int f2=2*no+1;
int mid = (l+r)>>1;
attT(f1,l,mid,pos,val);
attT(f2,mid+1,r,pos,val);
trT[no] = min(trT[f1],trT[f2]);
}
int findT(int no, int l, int r, int val) {
if(l == r) return l;
int f1 = 2*no;
int f2 = 2*no+1;
int mid = (l+r)/2;
if(trT[f2] <= val) return findT(f2,mid+1,r,val);
return findT(f1,l,mid,val);
}
void solve() {
cin >> n >> d >> T;
d = min(d,n-1);
int ans = 0;
for(int i = 1; i <= n; i++) cin >> t[i];
buildT(1,1,n);
for(int i = 1; i <= n; i++) {
r[i] = 0;
for(int j = i; j >= 1; j--) {
if(t[j]-j <= T-i) {
r[i] = j;
break;
}
}
if(r[i]!=0) ans++;
// cout << i << " " << r[i] << endl;
}
//qtd[i] -> qtd de retas passando de i+1 pra i
for(int i = 1; i < n; i++) {
qtd[i] = 0;
for(int j = i+1; j <= n; j++) {
if(r[j] != 0 && r[j] <= i) qtd[i]++;
}
st.insert(mp(qtd[i],i));
// cout << i << " - " << qtd[i] << endl;
}
while(d--) {
auto it = st.end(); it--;
int id = it->sc;
st.erase(it);
//tira todos os j que tem r[j] <= id
for(int j = id+1; j <= n; j++) {
if(r[j] != 0 && r[j] <= id) {
//diminui a qtd dos que ele tinha aumentado
for(int i = r[j]; i < j; i++) {
st.erase(mp(qtd[i],i));
qtd[i]--;
st.insert(mp(qtd[i],i));
}
r[j] = 0;
ans--;
}
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
# | 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... |