# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054284 | cpdreamer | Financial Report (JOI21_financial) | C++14 | 96 ms | 6172 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.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define P pair
#define S second
#define F first
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void file(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int dp[(int)7001];
int max_value[(int)7001];
void solve(){
int n;
cin>>n;
int d;
cin>>d;
int A[n];
for(int i=0;i<n;i++)
cin>>A[i];
dp[0]=1;
max_value[0]=A[0];
for(int i=1;i<n;i++){
dp[i]=1;
int max_d=-1;
for(int j=1;j<=min(i,d);j++){
if(A[i]>max_value[i-j]){
if(dp[i-j]+1>dp[i]){
dp[i]=dp[i-j]+1;
max_d=A[i];
}
else{
if(dp[i-j]+1==dp[i]){
if(max_d==-1)
max_d=A[i];
else
max_d=min(max_d,A[i]);
}
}
}
else{
if(dp[i-j]>dp[i]){
dp[i]=dp[i-j];
max_d=max_value[i-j];
}
else{
if(dp[i-j]==dp[i]){
if(max_d==-1)
max_d=max_value[i-j];
else
max_d=min(max_d,max_value[i-j]);
}
}
}
}
if(dp[i]==1)
max_d=min(max_d,A[i]);
max_value[i]=max_d;
}
cout<<dp[n-1]<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
return 0;
}
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... |