# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1125117 | vinh1e2kg | Global Warming (CEOI18_glo) | C++20 | 51 ms | 2756 KiB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define ll long long
#define pii pair<int, int>
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define MS(a, v) memset(a, v, sizeof a)
#define REP(i, n) for(int i = 0; i < n; ++ i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++ i)
#define FOD(i, a, b) for(int i = (a); i >= (b); -- i)
#define TSun(TZ) freopen(TZ".inp", "r", stdin), freopen(TZ".out", "w", stdout)
template<class X, class Y>
bool maximize(X & x, const Y & y){
if(x < y){
x = y;
return true;
}
else return false;
}
template<class X, class Y>
bool minimize(X & x, const Y & y){
if(x > y){
x = y;
return true;
}
else return false;
}
const int MAXN = 200005;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
void add(int &a, int b){
a += b;
if(a >= MOD) a -= MOD;
}
void sub(int &a, int b){
a -= b;
if(a < 0) a += MOD;
}
int sumMOD(int &a, int b){
return a + b >= MOD ? a + b - MOD : a + b;
}
bool BIT(int mask, int i){
return (mask >> i & 1);
}
int MASK(int x){
return (1 << x);
}
int n, x, a[MAXN], f[MAXN], ans;
vector <ll> dp;
void solve(void){
cin >> n >> x;
FOR(i, 1, n){
cin >> a[i];
auto it = lower_bound(ALL(dp), a[i] + x);
f[i] = it - dp.begin() + 1;
it = lower_bound(ALL(dp), a[i]);
if(it == dp.end())
dp.PB(a[i]);
else
*it = a[i];
}
dp.clear();
FOD(i, n, 1){
auto it = lower_bound(ALL(dp), - a[i]);
maximize(ans, f[i] + it - dp.begin());
if(it == dp.end())
dp.PB(-a[i]);
else
*it = -a[i];
}
cout << ans;
}
int main(void){
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define TaZinh "test"
if(fopen(TaZinh".inp", "r"))
TSun(TaZinh);
int Sun = 1;
// cin >> Sun;
REP(love, Sun) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |