Submission #953416

#TimeUsernameProblemLanguageResultExecution timeMemory
953416RifalGlobal Warming (CEOI18_glo)C++14
28 / 100
2035 ms6996 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 1000000007 #define INF 1000000000 #define INF2 1000000000000000000 ///#define cin fin ///#define cout fout using namespace std; double const EPS = 1e-14; typedef long long ll; ///ofstream fout("herding.out"); ///ifstream fin("herding.in"); int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n; ll x; cin >> n >> x; ll arr[n+2] = {}; for(int i = 1; i <= n; i++) cin >> arr[i]; arr[n+1] = INF2; ll dp1[n+2] = {}, dp2[n+2] = {}; for(int i = 1; i <= n; i++) { for(int j = i-1; j >= 0; j--) { if(arr[j] < arr[i]) { dp1[i] = max(dp1[i],dp1[j]+1); } } } for(int i = n; i >= 1; i--) { for(int j = i+1; j <= n+1; j++) { if(arr[j] > arr[i]) { // cout << i << ' ' << j << ' ' << dp2[i] << ' ' << dp2[j] << 'i' << endl; dp2[i] = max(dp2[i],dp2[j]+1); } } } ll ans = 0; /* for(int i = 1; i <= n; i++) { cout << i << ' ' << dp2[i] << endl; } cout << "KKKK" << endl; for(int i = 1; i <= n; i++) { cout << i << ' ' << dp1[i] << endl; }*/ for(int i = 1; i <= n; i++) { for(int j = i-1; j >= 0; j--) { if(arr[i]+x > arr[j]) { ans = max(ans,dp2[i]+dp1[j]); } } } for(int i = n; i >= 1; i--) { for(int j = i+1; j <= n+1; j++) { if(arr[i]-x < arr[j]) { ans = max(ans,dp1[i]+dp2[j]); } } } cout << ans << endl; 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...