제출 #594698

#제출 시각아이디문제언어결과실행 시간메모리
594698bLICGlobal Warming (CEOI18_glo)C++17
17 / 100
79 ms7940 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.lower_bound(a[i]); if (it!=s.end()) s.erase(it); s.insert(a[i]); pref[i+1] = {sz(s), *--s.end()}; } for (int i =0 ;i<n;i++) a[i]*=-1; vi temp; int ans = pref[n-1].ft; for (int i = n-1;i>=0;i--){ auto it = lower_bound(all(temp), a[i]); if (it!=temp.end()) *it = a[i]; else temp.pb(a[i]); int inc = upper_bound(all(temp), -pref[i].sd+k)-temp.begin(); ans = max(ans, pref[i].ft+inc); } // 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"; } }

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:79:9: warning: unused variable 'i' [-Wunused-variable]
   79 |     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...