Submission #706500

# Submission time Handle Problem Language Result Execution time Memory
706500 2023-03-06T19:53:54 Z VladPislaru Global Warming (CEOI18_glo) C++17
100 / 100
109 ms 5288 KB
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("scmax.in");
ofstream fout ("scmax.out");

int n, x, nr;
int a[200005];
int dp[200005];
int dp2[200005];
int best[200005];
int best2[200005];
int ans;


void CB(int i)
{
    int st, dr, p, mij, val = a[i];
    if (val <= dp[1])
    {
        dp[1] = val;
        best[i] = 1;
        return;
    }

    if (val > dp[nr])
    {
        nr++;
        dp[nr] = val;
        best[i] = nr;
        return ;
    }

    /// caut cea mai din stanga poz. p cu a[i]<= dp[p]
    st = 1; dr = nr; p = nr;
    while (st <= dr)
    {
        mij = (st + dr) / 2;
        if (val <= dp[mij])
        {
            p = mij;
            dr = mij - 1;
        }
        else st = mij + 1;
    }
    dp[p] = val;
    best[i] = p;
}

int Get_ans(int i) {
    int st, dr, mij, val = a[i] - x, p;
    if (val >= dp2[1])
        return 1;
    if (val < dp2[nr])
        return nr + 1;
    st = 1, dr = nr, p = nr;
    while (st <= dr) {
        mij = (st + dr) / 2;
        if (val >= dp2[mij]) {
            p = mij;
            dr = mij - 1;
        }
        else st = mij + 1;
    }
    return p;
}

void CB2 (int i) {
    int st, dr, mij, val = a[i], p;
    if (val >= dp2[1]) {
        dp2[1] = val;
        return;
    }
    else if (val < dp2[nr]) {
        nr++;
        dp2[nr] = val;
        return;
    }
    st = 1, dr = nr, p = nr;
    while (st <= dr) {
        mij = (st + dr) / 2;
        if (val >= dp2[mij]) {
            p = mij;
            dr = mij - 1;
        }
        else st = mij + 1;
    }
    dp2[p] = val;
}
int main()
{
    cin >> n >> x;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    best[1] = 1;
    dp[1] = a[1];
    dp[0] = 0;
    nr = 1;
    for (int i = 2; i <= n; i++) {
        CB(i);
    }
    ans = nr;
    best2[n] = 1;
    dp2[1] = a[n];
    nr = 1;

    for (int i = n - 1; i > 0; i--) {
        best2[i] = Get_ans(i);
        CB2(i);
        ////cout << best2[i] << "\n";
        ans = max(best[i] + best2[i] - 1, ans);
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 4524 KB Output is correct
2 Correct 107 ms 4488 KB Output is correct
3 Correct 107 ms 4524 KB Output is correct
4 Correct 98 ms 4524 KB Output is correct
5 Correct 55 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1364 KB Output is correct
2 Correct 25 ms 1324 KB Output is correct
3 Correct 24 ms 1268 KB Output is correct
4 Correct 15 ms 1344 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 17 ms 1364 KB Output is correct
7 Correct 22 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2424 KB Output is correct
2 Correct 48 ms 2392 KB Output is correct
3 Correct 98 ms 4532 KB Output is correct
4 Correct 60 ms 4576 KB Output is correct
5 Correct 29 ms 2380 KB Output is correct
6 Correct 51 ms 4480 KB Output is correct
7 Correct 69 ms 5068 KB Output is correct
8 Correct 43 ms 2408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 109 ms 4524 KB Output is correct
28 Correct 107 ms 4488 KB Output is correct
29 Correct 107 ms 4524 KB Output is correct
30 Correct 98 ms 4524 KB Output is correct
31 Correct 55 ms 4556 KB Output is correct
32 Correct 25 ms 1364 KB Output is correct
33 Correct 25 ms 1324 KB Output is correct
34 Correct 24 ms 1268 KB Output is correct
35 Correct 15 ms 1344 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 17 ms 1364 KB Output is correct
38 Correct 22 ms 1356 KB Output is correct
39 Correct 47 ms 2424 KB Output is correct
40 Correct 48 ms 2392 KB Output is correct
41 Correct 98 ms 4532 KB Output is correct
42 Correct 60 ms 4576 KB Output is correct
43 Correct 29 ms 2380 KB Output is correct
44 Correct 51 ms 4480 KB Output is correct
45 Correct 69 ms 5068 KB Output is correct
46 Correct 43 ms 2408 KB Output is correct
47 Correct 48 ms 2460 KB Output is correct
48 Correct 49 ms 2380 KB Output is correct
49 Correct 100 ms 4524 KB Output is correct
50 Correct 57 ms 4480 KB Output is correct
51 Correct 44 ms 3656 KB Output is correct
52 Correct 58 ms 4644 KB Output is correct
53 Correct 58 ms 4632 KB Output is correct
54 Correct 74 ms 5288 KB Output is correct
55 Correct 87 ms 4556 KB Output is correct