Submission #483423

# Submission time Handle Problem Language Result Execution time Memory
483423 2021-10-29T10:51:49 Z benk Global Warming (CEOI18_glo) C++17
100 / 100
47 ms 2764 KB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)      x.begin(), x.end()
#define pb          push_back
#define sz(x)       (int)(x.size())
#define ll          long long
#define fi          first
#define se          second
#define lbd         lower_bound
#define ubd         upper_bound

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

const int MOD = 1e9 + 7;
const double eps = 1e-10;
const long long INF = 1e18;
const int N = 2e5 + 10;


void solve() {
	int n, x;
	cin >> n >> x;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<int> lds(n), dp;
	for (int i = n - 1; i >= 0; i--) {
		auto it = lbd(all(dp), -v[i] + x) - dp.begin();
		lds[i] = it + 1;
		it = lbd(all(dp), -v[i]) - dp.begin();
		if (it == sz(dp)) dp.pb(-v[i]);
		else dp[it] = -v[i];
	}
	dp = vector<int>();
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int it = lbd(all(dp), v[i]) - dp.begin();
		if (it == sz(dp)) dp.pb(v[i]);
		else dp[it] = v[i];
		ans = max(ans, it + lds[i]);
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2004 KB Output is correct
2 Correct 45 ms 1876 KB Output is correct
3 Correct 45 ms 1868 KB Output is correct
4 Correct 46 ms 1872 KB Output is correct
5 Correct 28 ms 2752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 716 KB Output is correct
2 Correct 11 ms 648 KB Output is correct
3 Correct 11 ms 716 KB Output is correct
4 Correct 7 ms 876 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 876 KB Output is correct
7 Correct 10 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1100 KB Output is correct
2 Correct 21 ms 1112 KB Output is correct
3 Correct 42 ms 1868 KB Output is correct
4 Correct 26 ms 2764 KB Output is correct
5 Correct 12 ms 1548 KB Output is correct
6 Correct 21 ms 2584 KB Output is correct
7 Correct 26 ms 2620 KB Output is correct
8 Correct 18 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 47 ms 2004 KB Output is correct
28 Correct 45 ms 1876 KB Output is correct
29 Correct 45 ms 1868 KB Output is correct
30 Correct 46 ms 1872 KB Output is correct
31 Correct 28 ms 2752 KB Output is correct
32 Correct 11 ms 716 KB Output is correct
33 Correct 11 ms 648 KB Output is correct
34 Correct 11 ms 716 KB Output is correct
35 Correct 7 ms 876 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 7 ms 876 KB Output is correct
38 Correct 10 ms 716 KB Output is correct
39 Correct 27 ms 1100 KB Output is correct
40 Correct 21 ms 1112 KB Output is correct
41 Correct 42 ms 1868 KB Output is correct
42 Correct 26 ms 2764 KB Output is correct
43 Correct 12 ms 1548 KB Output is correct
44 Correct 21 ms 2584 KB Output is correct
45 Correct 26 ms 2620 KB Output is correct
46 Correct 18 ms 1108 KB Output is correct
47 Correct 22 ms 1224 KB Output is correct
48 Correct 22 ms 1048 KB Output is correct
49 Correct 46 ms 1868 KB Output is correct
50 Correct 27 ms 2756 KB Output is correct
51 Correct 23 ms 2404 KB Output is correct
52 Correct 26 ms 2764 KB Output is correct
53 Correct 22 ms 2756 KB Output is correct
54 Correct 26 ms 2760 KB Output is correct
55 Correct 36 ms 1880 KB Output is correct