Submission #785284

#TimeUsernameProblemLanguageResultExecution timeMemory
785284devariaotaGlobal Warming (CEOI18_glo)C++17
10 / 100
100 ms262144 KiB
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, x;
int arr[200004], dp[200004];
signed main() {
    ioss;
    cin >> n >> x;
    for(int i = 0; i < n; i++) cin >> arr[i];
    if(x == 0) {
        vector<int> tmp;
        for(int i = 0; i < n; i++) {
            if(i == 0) {
                dp[i] = 1;
                tmp.pb(arr[i]);
                continue;
            }
            if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
            else {
                int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
                tmp[cur] = arr[i];
                dp[i] = dp[i-1];
                // for(auto x : tmp) cout << x << " ";
                // cout << endl;
            }
            // cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
        }
        cout << dp[n-1] << endl;
        return 0;
    }

    vector<pii> range;
    int maxx[n+2][n+2] = {};
    for(int j = 0; j < n; j++) {
        int tmp = arr[j];
        for(int k = j; k < n; k++) {
            range.pb({j, k});
            tmp = max(tmp, arr[k]);
            maxx[j][k] = tmp;
        }
    }

    int ans = 0;
    for(auto [l, r] : range) {
        // cout << l << " " << r << endl;
        vector<int> tmp;
        memset(dp, 0, sizeof(dp));
        for(int i = 0; i < n; i++) {
            if(i >= l && i <= r && maxx[l][r] <= x) arr[i] -= maxx[l][r];
            if(i == 0) {
                dp[i] = 1;
                tmp.pb(arr[i]);
                if(i >= l && i <= r && maxx[l][r] <= x) arr[i] += maxx[l][r];
                continue;
            }
            if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
            else {
                int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
                tmp[cur] = arr[i];
                dp[i] = dp[i-1];
                // for(auto x : tmp) cout << x << " ";
                // cout << endl;
            }
            if(i >= l && i <= r && maxx[l][r] <= x) arr[i] += maxx[l][r];
        }
        ans = max(ans, dp[n-1]);
        // cout << " :: " << l << " " << r << " " << maxx[l][r] << " " << dp[n-1] << endl;
    }
    cout << ans << endl;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...