#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 2*1e3+5;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int main(){
optimise;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
//setIO("nocross");
int n,k;
cin>>n>>k;
vi tab(n);
for (int i = 0; i < n; ++i)
{
cin>>tab[i];
}
vi pre(n,0);
vi dp(n,1e9+5);
int longest=0;
for(int i=0;i<n;i++)
{
int j=lower_bound(dp.begin(),dp.end(),tab[i])-dp.begin();
dp[j]=tab[i];
pre[i]=j+1;
longest=max(longest,pre[i]);
}//cout << longest<<endl;
dp.assign(n,1e9+5);
for (int i = n-1; i >= 0; --i)
{
int j=lower_bound(dp.begin(),dp.end(),-tab[i]+k)-dp.begin();//cout<<j<<endl;
longest=max(longest,pre[i]+j);
j=lower_bound(dp.begin(),dp.end(),-tab[i])-dp.begin();
dp[j]=-tab[i];
}cout <<longest<<endl;
}
Compilation message
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
2648 KB |
Output is correct |
2 |
Correct |
50 ms |
4548 KB |
Output is correct |
3 |
Correct |
50 ms |
4552 KB |
Output is correct |
4 |
Correct |
48 ms |
4600 KB |
Output is correct |
5 |
Correct |
38 ms |
3784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
852 KB |
Output is correct |
2 |
Correct |
12 ms |
1356 KB |
Output is correct |
3 |
Correct |
12 ms |
1288 KB |
Output is correct |
4 |
Correct |
11 ms |
1236 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1096 KB |
Output is correct |
7 |
Correct |
10 ms |
1412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1488 KB |
Output is correct |
2 |
Correct |
23 ms |
2376 KB |
Output is correct |
3 |
Correct |
51 ms |
4544 KB |
Output is correct |
4 |
Correct |
36 ms |
3792 KB |
Output is correct |
5 |
Correct |
19 ms |
2096 KB |
Output is correct |
6 |
Correct |
29 ms |
3668 KB |
Output is correct |
7 |
Correct |
34 ms |
4464 KB |
Output is correct |
8 |
Correct |
19 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
48 ms |
2648 KB |
Output is correct |
28 |
Correct |
50 ms |
4548 KB |
Output is correct |
29 |
Correct |
50 ms |
4552 KB |
Output is correct |
30 |
Correct |
48 ms |
4600 KB |
Output is correct |
31 |
Correct |
38 ms |
3784 KB |
Output is correct |
32 |
Correct |
11 ms |
852 KB |
Output is correct |
33 |
Correct |
12 ms |
1356 KB |
Output is correct |
34 |
Correct |
12 ms |
1288 KB |
Output is correct |
35 |
Correct |
11 ms |
1236 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
10 ms |
1096 KB |
Output is correct |
38 |
Correct |
10 ms |
1412 KB |
Output is correct |
39 |
Correct |
25 ms |
1488 KB |
Output is correct |
40 |
Correct |
23 ms |
2376 KB |
Output is correct |
41 |
Correct |
51 ms |
4544 KB |
Output is correct |
42 |
Correct |
36 ms |
3792 KB |
Output is correct |
43 |
Correct |
19 ms |
2096 KB |
Output is correct |
44 |
Correct |
29 ms |
3668 KB |
Output is correct |
45 |
Correct |
34 ms |
4464 KB |
Output is correct |
46 |
Correct |
19 ms |
2380 KB |
Output is correct |
47 |
Correct |
24 ms |
2376 KB |
Output is correct |
48 |
Correct |
25 ms |
2368 KB |
Output is correct |
49 |
Correct |
49 ms |
4568 KB |
Output is correct |
50 |
Correct |
36 ms |
3792 KB |
Output is correct |
51 |
Correct |
33 ms |
2948 KB |
Output is correct |
52 |
Correct |
37 ms |
3924 KB |
Output is correct |
53 |
Correct |
33 ms |
4028 KB |
Output is correct |
54 |
Correct |
36 ms |
4548 KB |
Output is correct |
55 |
Correct |
40 ms |
4552 KB |
Output is correct |