Submission #1104184

#TimeUsernameProblemLanguageResultExecution timeMemory
1104184vjudge1Global Warming (CEOI18_glo)C++17
100 / 100
42 ms4308 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; int ar[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, g; cin >> n >> g; for(int i=1; i<=n; ++i) cin >> ar[i]; int res = 1; int dp[n+1]; dp[0] = 0; vector<int> lis; for(int i=1; i<=n; ++i) { auto t = lower_bound(lis.begin(), lis.end(), ar[i]); dp[i] = t - lis.begin() + 1; if(t == lis.end()) lis.emplace_back(ar[i]); else *t = ar[i]; //cout << dp[i] << " \n"[i == n]; } res = lis.size(); lis.clear(); for(int i=n; i>=1; --i) { int x = lower_bound(lis.begin(), lis.end(), -ar[i] + 2*g) - lis.begin(); //cout << "I: " << i << " => "; //for(auto x : lis) cout << x << ' '; //cout << " | " << x << endl; res = max(res, dp[i] + x ); int y = lower_bound(lis.begin(), lis.end(), -ar[i] + g) - lis.begin(); if(y == lis.size()) lis.emplace_back(-ar[i] + g); else lis[y] = -ar[i] + g; } cout << res << '\n'; return 0; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:37:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     if(y == lis.size()) lis.emplace_back(-ar[i] + g);
      |        ~~^~~~~~~~~~~~~
#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...