This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MXN = 1e6 + 10;
const ll INF = 1e9;
ll n;
ll A[MXN], dp[MXN], pd[MXN];
int main(){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++) cin >> A[i];
sort(A + 1, A + n + 1, greater<ll>());
ll ans = 0;
for(int i = 1; i <= n; i ++){
ll rem = A[i];
if(n - i + 1 < rem) continue;
ans ++;
i = i + rem - 1;
}
reverse(A + 1, A + n + 1);
for(int i = 1; i <= n; i ++){
if(A[i] > i){
dp[i] = dp[i - 1];
pd[i] = -INF;
continue;
}
pd[i] = dp[i - A[i]] + 1;
dp[i] = max(pd[i], dp[i - 1]);
}
cout << pd[n] << '\n';
ans = min(ans, dp[n]);
//cout << ans << '\n';
return 0;
}
# | 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... |
# | 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... |