Submission #1218749

#TimeUsernameProblemLanguageResultExecution timeMemory
1218749muhammadali_2009Global Warming (CEOI18_glo)C++20
0 / 100
32 ms4932 KiB
// +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ // #include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define endl '\n' #define ll long long #define int long long #define all(x) x.begin(), x.end() #define all1(x) x.rbegin(), x.rend() #define seea(x) for(int i = 0; i < x; i++) #define pb push_back #define ff first #define vc vector #define ss second using namespace std; const int mod = 1e9 + 7; int lis(vector<int>a){ int n = a.size(); vector<int>dp; for(int i = 0; i < n; i ++){ auto id = lower_bound(dp.begin(), dp.end(), a[i]); if(id == dp.end()){ dp.push_back(a[i]); } else dp[id - dp.begin()] = a[i]; } return dp.size(); } void solve() { int ans = 1; int n, x; cin >> n >> x; vector<int>a(n), dp; seea(n) cin >> a[i]; //pref[i] -> i-indeksgacha va i ni olgandagi lis //suf[i] -> 1 .. i - indeks -x qilingandagi va i - indexdan n - gacha lis vector<int>pref(n + 1); for(int i = 1; i <= n; i ++){ auto id = lower_bound(dp.begin(), dp.end(), a[i - 1]); if(id == dp.end()){ dp.push_back(a[i - 1]); } else{ dp[id - dp.begin()] = a[i - 1]; } pref[i] = dp.size(); ans = max(ans, pref[i]); } vector<int> suf(n + 2), dp2; for(int i = n; i >= 1; --i){ int v = -a[i - 1] + x; auto it = lower_bound(dp2.begin(), dp2.end(), v); if(it == dp2.end()) dp2.push_back(v); else *it = v; suf[i] = dp2.size(); } for(int i = 0; i <= n; ++i){ int l = (i == 0 ? 0 : pref[i]); int r = (i == n ? 0 : suf[i + 1]); ans = max(ans, l + r - 1); } cout << ans << endl; } signed main(){ fast; int t = 1; //cin >> t; while (t--){ solve(); } }
#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...