162222025-04-14 17:57:57gortomiNövekvő Ödön és a Másoló Varázslócpp17Wrong answer 0/100224ms15156 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int inf = 1e9 + 5;
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 2), b(m);
    for(int i = 1; i <= n; i++) cin >> a[i];
    a[n + 1] = inf;
    for(int j = 0; j < m; j++) cin >> b[j];
    sort(b.begin(), b.end());
    vector<int> dp(n + 2);
    set<array<int, 3> > s;
    s.insert({0, 0});
    for(int i = 1; i <= n + 1; i++)
    {
        int ind = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        int val = a[i] - i + 1;
        auto it = s.lower_bound({val, a[i], -inf});
        if(it == s.begin())
        {
            dp[i] = n + 1;
            continue;
        }
        it--;
        dp[i] = (*it)[2] + i - 1;
        //cout << i << " " << dp[i] << " " << val << " " << it -> first << " " << it -> second << "\n";
        int ins = a[i] - i, ival = dp[i] - i;
        while(1)
        {
            auto it2 = s.lower_bound({ins, a[i], -inf});
            if(it2 != s.end() && (*it2)[2] >= ival) s.erase(it2);
            else break;
        }
        s.insert({ins, a[i], ival});

    }
    cout << dp[n + 1] << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Wrong answer41ms2872 KiB
subtask20/5
3Accepted48ms1080 KiB
4Accepted48ms1076 KiB
5Wrong answer50ms1076 KiB
subtask30/10
6Wrong answer1ms316 KiB
7Wrong answer1ms316 KiB
8Wrong answer1ms316 KiB
subtask40/15
9Wrong answer1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms320 KiB
12Wrong answer1ms332 KiB
subtask50/5
13Wrong answer4ms500 KiB
14Wrong answer4ms316 KiB
15Wrong answer4ms464 KiB
subtask60/5
16Wrong answer4ms316 KiB
17Wrong answer4ms716 KiB
18Wrong answer4ms464 KiB
19Wrong answer4ms316 KiB
subtask70/10
20Wrong answer4ms600 KiB
21Wrong answer4ms720 KiB
22Wrong answer4ms316 KiB
23Wrong answer3ms448 KiB
24Wrong answer4ms564 KiB
subtask80/25
25Wrong answer48ms1476 KiB
26Accepted48ms1584 KiB
27Accepted46ms1584 KiB
28Accepted1ms316 KiB
29Wrong answer82ms1624 KiB
30Wrong answer108ms7736 KiB
31Wrong answer104ms7616 KiB
32Wrong answer90ms7628 KiB
33Wrong answer87ms6964 KiB
34Wrong answer86ms7108 KiB
35Wrong answer82ms6592 KiB
36Wrong answer104ms7624 KiB
37Wrong answer92ms7732 KiB
38Wrong answer85ms6708 KiB
39Wrong answer82ms1488 KiB
40Wrong answer57ms1472 KiB
41Wrong answer85ms6452 KiB
42Wrong answer52ms4248 KiB
43Wrong answer105ms7620 KiB
44Wrong answer98ms7628 KiB
45Wrong answer86ms7220 KiB
subtask90/25
46Wrong answer202ms15088 KiB
47Wrong answer180ms13876 KiB
48Wrong answer224ms15156 KiB
49Wrong answer168ms2768 KiB
50Wrong answer170ms2772 KiB
51Wrong answer168ms2780 KiB
52Wrong answer144ms11024 KiB
53Wrong answer168ms12596 KiB
54Wrong answer177ms13620 KiB
55Wrong answer112ms2760 KiB