Submission #314070

#TimeUsernameProblemLanguageResultExecution timeMemory
314070tushar_2658Global Warming (CEOI18_glo)C++14
100 / 100
86 ms7800 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 200005; using ll = long long; ll a[maxn], x; int n; int main(int argc, char const *argv[]) { scanf("%d %lld", &n, &x); for(int i = 1; i <= n; ++i){ scanf("%lld", &a[i]); } vector<ll> dp(n + 1, 1e15); dp[0] = -1e15; vector<int> L(n + 1); for(int i = 1; i <= n; ++i){ int idx = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin(); dp[idx] = a[i]; L[i] = idx; } vector<ll> dp1(n + 1, 1e15); dp1[0] = -1e15; int ans = 0; for(int i = n; i >= 1; --i){ int idx = lower_bound(dp1.begin(), dp1.end(), -a[i]) - dp1.begin(); int idx1 = lower_bound(dp1.begin(), dp1.end(), -a[i] + x) - dp1.begin(); dp1[idx] = -a[i]; ans = max(ans, L[i] + idx1 - 1); } cout << ans << endl; return 0; }

Compilation message (stderr)

glo.cpp: In function 'int main(int, const char**)':
glo.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |   scanf("%d %lld", &n, &x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
glo.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%lld", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
#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...