제출 #490454

#제출 시각아이디문제언어결과실행 시간메모리
490454fun_dayGlobal Warming (CEOI18_glo)C++14
28 / 100
2084 ms1864 KiB
#include <bits/stdc++.h> using namespace std; int get_lis(vector<int> v){ int n = (int)v.size(); if(n == 0) return 0; vector<int> lis; for(int i = 0 ; i < n ; i++){ int val = v[i]; auto q = lower_bound(lis.begin(),lis.end() , val); if(q == lis.end()){ lis.emplace_back(val); } else{ *q = val; } } return (int)lis.size(); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n , x; cin >> n >> x; vector<int> v(n); for(int i = 0 ; i < n ; i++){ cin >> v[i]; } vector<int> dp(n , 1); for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < i ; j++){ if(v[j] < v[i]){ dp[i] = max(dp[i] , dp[j] + 1); } } } int best = 0; for(int i = 0 ; i < n ; i++){ int val = v[i]; vector<int> s; for(int j = i + 1 ; j < n ; j++){ if(v[j] + x > val) s.emplace_back(v[j] + x); } best = max(best , dp[i] + get_lis(s)); s.clear(); for(int j = i + 1 ; j < n ; j++){ if(v[j] > val - x) s.emplace_back(v[j]); } best = max(best , dp[i] + get_lis(s)); } cout << best << '\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...