Submission #594663

#TimeUsernameProblemLanguageResultExecution timeMemory
594663bLICGlobal Warming (CEOI18_glo)C++17
15 / 100
99 ms8848 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)(x).size() #define ft first #define sd second #define pb push_back #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef pair<ll, ll> pll; typedef vector<pll> vll; typedef vector<vi> vvi; #define dbg if(1) void printbit(int x) {string s="\n";while(x){s+=((x%2)?'1':'0');x/=2;} reverse(all(s)); cout<<s;} const ll MOD = 1e9+7; const int INF = 1e9; const int N = 2501; void solve(){ int n, k; cin>>n>>k; int a[n]; for (int i =0;i<n;i++) cin>>a[i]; set<int> s; vii pref(n+1, {0,-INF}); for (int i = 0;i<n;i++){ auto it = s.upper_bound(a[i]); if (it!=s.end()) s.erase(it); s.insert(a[i]); pref[i+1] = {sz(s), *--s.end()}; } s.clear(); vii suff(n+1, {0,INF}); for (int i = n-1;i>=0;i--){ auto it = s.upper_bound(a[i]); if (it!=s.begin()) s.erase(--it); s.insert(a[i]); suff[i] = {sz(s), *s.begin()}; } int ans = 0; for (int i = 0;i<=n;i++) { if (pref[i].ft+suff[i].ft>ans && pref[i].sd-k<suff[i].sd){ ans = pref[i].ft+suff[i].ft; } } cout<<ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // #ifdef ONLINE_JUDGE // freopen("timeline.in", "r", stdin); // freopen("timeline.out", "w", stdout); // #endif int t = 1; // cin>>t; int i = 0; while(t--){ // cout<<"Case #"<<++i<<": "; solve(); cout<<"\n"; } }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:81:9: warning: unused variable 'i' [-Wunused-variable]
   81 |     int i = 0;
      |         ^
#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...