제출 #131683

#제출 시각아이디문제언어결과실행 시간메모리
131683apostoldaniel854Global Warming (CEOI18_glo)C++14
5 / 100
192 ms3960 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5, INF = 2e9 + 7; int nr; int sol[1 + N], poz[1 + N], scm[1 + N]; int a[1 + N]; inline int get (int n, int orient) { int st, dr, p; st = 1; dr = nr; if (orient) p = nr + 1; else p = 0; while (st <= dr) { int mij = (st + dr) / 2; if ((sol[mij] > n && orient) || (sol[mij] < n && !orient)) { dr = mij - 1; p = mij; } else st = mij + 1; } return p; } int main() { int n, x; cin >> n >> x; for (int i = 1; i <= n; i++) cin >> a[i]; sol[1] = INF; nr = 1; for (int i = n; i > 0; i--) { if (a[i] < sol[nr]) { nr++; poz[i] = nr; sol[nr] = a[i]; } else { int p = get (a[i], 0); sol[p] = a[i]; poz[i] = p; } } sol[1] = 0; nr = 1; int ans = 0; for (int i = 1; i <= n; i++) { int p; if (a[i] + x > sol[nr]) p = nr + 1; else p = get (a[i], x + 1); //cout << p << "\n"; ans = max (ans, poz[i] + p - 3); if (a[i] > sol[nr]) { nr++; sol[nr] = a[i]; } else { int p = get (a[i], 1); sol[p] = a[i]; } } cout << ans << "\n"; return 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...