Submission #99571

# Submission time Handle Problem Language Result Execution time Memory
99571 2019-03-05T10:48:41 Z Mercenary Global Warming (CEOI18_glo) C++14
100 / 100
62 ms 4216 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "TEST"
#define pb	push_back
#define mp 	make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;

int n , x , a[maxn];
int prefix[maxn];

void enter()
{
    cin >> n >> x;
    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];
}

int b[maxn];

void solve()
{
    int m = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
        int k = lower_bound(b + 1 , b + m + 1 , a[i]) - b;
        b[k] = a[i];
        m = max(m , k);
        prefix[i] = k;
    }
    int res = 0;
    m = 0;
    for(int i = n ; i >= 1 ; --i)
    {
        res = max(res , min(m , int(lower_bound(b + 1 , b + m + 1 , a[i] , greater<int>()) - b) - 1) + prefix[i]);
        int k = lower_bound(b + 1 , b + m + 1 , a[i] + x , greater<int>()) - b;
        b[k] = a[i] + x;
        m = max(m , k);
    }
    cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    enter();
    solve();
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:51:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
glo.cpp:51:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3832 KB Output is correct
2 Correct 58 ms 3824 KB Output is correct
3 Correct 59 ms 3960 KB Output is correct
4 Correct 60 ms 3832 KB Output is correct
5 Correct 37 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1152 KB Output is correct
2 Correct 18 ms 1280 KB Output is correct
3 Correct 16 ms 1280 KB Output is correct
4 Correct 10 ms 1152 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 14 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2048 KB Output is correct
2 Correct 29 ms 2048 KB Output is correct
3 Correct 58 ms 3796 KB Output is correct
4 Correct 41 ms 3456 KB Output is correct
5 Correct 21 ms 1912 KB Output is correct
6 Correct 34 ms 3448 KB Output is correct
7 Correct 35 ms 4088 KB Output is correct
8 Correct 29 ms 2068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 59 ms 3832 KB Output is correct
28 Correct 58 ms 3824 KB Output is correct
29 Correct 59 ms 3960 KB Output is correct
30 Correct 60 ms 3832 KB Output is correct
31 Correct 37 ms 3448 KB Output is correct
32 Correct 15 ms 1152 KB Output is correct
33 Correct 18 ms 1280 KB Output is correct
34 Correct 16 ms 1280 KB Output is correct
35 Correct 10 ms 1152 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 10 ms 1152 KB Output is correct
38 Correct 14 ms 1280 KB Output is correct
39 Correct 26 ms 2048 KB Output is correct
40 Correct 29 ms 2048 KB Output is correct
41 Correct 58 ms 3796 KB Output is correct
42 Correct 41 ms 3456 KB Output is correct
43 Correct 21 ms 1912 KB Output is correct
44 Correct 34 ms 3448 KB Output is correct
45 Correct 35 ms 4088 KB Output is correct
46 Correct 29 ms 2068 KB Output is correct
47 Correct 34 ms 2148 KB Output is correct
48 Correct 45 ms 2044 KB Output is correct
49 Correct 62 ms 3856 KB Output is correct
50 Correct 58 ms 3448 KB Output is correct
51 Correct 49 ms 2680 KB Output is correct
52 Correct 56 ms 3576 KB Output is correct
53 Correct 33 ms 3576 KB Output is correct
54 Correct 38 ms 4216 KB Output is correct
55 Correct 55 ms 3832 KB Output is correct