Submission #259949

#TimeUsernameProblemLanguageResultExecution timeMemory
259949pedroslreyGlobal Warming (CEOI18_glo)C++17
100 / 100
85 ms3596 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int INF = 2e9; int xs[MAXN]; int dp_lis[MAXN]; int dp_lds[MAXN]; int pos[MAXN]; int main() { int n, x; scanf("%d %d", &n, &x); for (int i = 1; i <= n; ++i) scanf("%d", &xs[i]); for (int i = 1; i <= n; ++i) dp_lis[i] = INF; int ans = 0; for (int i = 1; i <= n; ++i) { int p = lower_bound(dp_lis, dp_lis + n + 1, xs[i]) - dp_lis; dp_lis[p] = xs[i]; ans = max(ans, p); pos[i] = p; } for(int i = 1; i <= n; ++i) dp_lds[i] = INF; dp_lds[0] = -INF; for (int i = n; i >= 1; --i) { int idx = lower_bound(dp_lds, dp_lds + n + 1, -xs[i]) - dp_lds - 1; int p = lower_bound(dp_lds, dp_lds + n + 1, -xs[i] - x) - dp_lds; dp_lds[p] = -xs[i] - x; ans = max(ans, pos[i] + idx); } printf("%d\n", ans); }

Compilation message (stderr)

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