Submission #586609

#TimeUsernameProblemLanguageResultExecution timeMemory
586609aris12345678Global Warming (CEOI18_glo)C++14
100 / 100
48 ms4424 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N, X; scanf("%d %d", &N, &X); vector<int> A(N); for(int i = 0; i < N; i++) scanf("%d", &A[i]); vector<int> LIS; vector<int> INC(N, 0); LIS.push_back(A[0]); INC[0] = 1; for(int i = 1; i < N; i++) { int pos = lower_bound(LIS.begin(), LIS.end(), A[i])-LIS.begin(); INC[i] = pos+1; if(pos < LIS.size()) LIS[pos] = A[i]; else LIS.push_back(A[i]); } LIS.clear(); LIS.push_back(-A[N-1]); int ans = 0; for(int i = N-2; i >= 0; i--) { int len = lower_bound(LIS.begin(), LIS.end(), -A[i]+X)-LIS.begin(); ans = max(ans, INC[i]+len); int pos = lower_bound(LIS.begin(), LIS.end(), -A[i])-LIS.begin(); if(pos < LIS.size()) LIS[pos] = -A[i]; else LIS.push_back(-A[i]); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         if(pos < LIS.size())
      |            ~~~~^~~~~~~~~~~~
glo.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if(pos < LIS.size())
      |            ~~~~^~~~~~~~~~~~
glo.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d %d", &N, &X);
      |     ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         scanf("%d", &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...