Submission #887064

# Submission time Handle Problem Language Result Execution time Memory
887064 2023-12-13T15:42:52 Z dsyz Global Warming (CEOI18_glo) C++17
100 / 100
54 ms 8620 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,X;
	cin>>N>>X;
	ll arr[N];
	for(ll i = 0;i < N;i++){
		cin>>arr[i];
	}
	//we can prove that it is always optimal to subtract x from prefix [0,i] because obviously we want the first few elements as small as possible, it will do no worse than subtracting x from [j,i]
	//since we are subtracting from the prefix, we should obviously subtract as much as possible which is x
	vector<ll> v(N,1e18);
	ll longestprefix[N];
	ll ans = 0;
	for(ll i = 0;i < N;i++){
		auto it = lower_bound(v.begin(),v.end(),arr[i]);
		v[it - v.begin()] = arr[i];
		longestprefix[i] = it - v.begin() + 1;
		ans = max(ans,longestprefix[i]);
	}
	v.clear();
	v = vector<ll>(N, 1e18);
	for(ll i = N - 1;i >= 0;i--){
		ll pos = lower_bound(v.begin(),v.end(),-arr[i] + X) - v.begin();
		ans = max(ans,longestprefix[i] + pos);
		ll insert_pos = lower_bound(v.begin(),v.end(),-arr[i]) - v.begin();
		v[insert_pos] = -arr[i];
	}
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8532 KB Output is correct
2 Correct 49 ms 8540 KB Output is correct
3 Correct 54 ms 8508 KB Output is correct
4 Correct 48 ms 8528 KB Output is correct
5 Correct 35 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2396 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 13 ms 2396 KB Output is correct
4 Correct 9 ms 2136 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2152 KB Output is correct
7 Correct 9 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4504 KB Output is correct
2 Correct 21 ms 4444 KB Output is correct
3 Correct 43 ms 8620 KB Output is correct
4 Correct 35 ms 7772 KB Output is correct
5 Correct 18 ms 3932 KB Output is correct
6 Correct 29 ms 7376 KB Output is correct
7 Correct 32 ms 8016 KB Output is correct
8 Correct 17 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 0 ms 376 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 51 ms 8532 KB Output is correct
28 Correct 49 ms 8540 KB Output is correct
29 Correct 54 ms 8508 KB Output is correct
30 Correct 48 ms 8528 KB Output is correct
31 Correct 35 ms 7768 KB Output is correct
32 Correct 11 ms 2396 KB Output is correct
33 Correct 11 ms 2396 KB Output is correct
34 Correct 13 ms 2396 KB Output is correct
35 Correct 9 ms 2136 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 9 ms 2152 KB Output is correct
38 Correct 9 ms 2396 KB Output is correct
39 Correct 21 ms 4504 KB Output is correct
40 Correct 21 ms 4444 KB Output is correct
41 Correct 43 ms 8620 KB Output is correct
42 Correct 35 ms 7772 KB Output is correct
43 Correct 18 ms 3932 KB Output is correct
44 Correct 29 ms 7376 KB Output is correct
45 Correct 32 ms 8016 KB Output is correct
46 Correct 17 ms 4440 KB Output is correct
47 Correct 26 ms 4568 KB Output is correct
48 Correct 23 ms 4444 KB Output is correct
49 Correct 50 ms 8616 KB Output is correct
50 Correct 35 ms 7772 KB Output is correct
51 Correct 29 ms 5968 KB Output is correct
52 Correct 36 ms 7760 KB Output is correct
53 Correct 30 ms 7952 KB Output is correct
54 Correct 34 ms 8532 KB Output is correct
55 Correct 39 ms 8572 KB Output is correct