162232025-04-14 18:06:48gortomiNövekvő Ödön és a Másoló Varázslócpp17Wrong answer 0/100224ms15240 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
3Accepted48ms1076 KiB
4Accepted48ms1076 KiB
5Wrong answer48ms1076 KiB
subtask30/10
6Wrong answer1ms316 KiB
7Wrong answer1ms508 KiB
8Wrong answer1ms316 KiB
subtask40/15
9Wrong answer1ms320 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms388 KiB
subtask50/5
13Wrong answer4ms504 KiB
14Wrong answer4ms316 KiB
15Wrong answer4ms316 KiB
subtask60/5
16Wrong answer4ms316 KiB
17Wrong answer4ms564 KiB
18Wrong answer4ms564 KiB
19Wrong answer4ms316 KiB
subtask70/10
20Wrong answer4ms564 KiB
21Wrong answer4ms564 KiB
22Wrong answer4ms316 KiB
23Wrong answer3ms620 KiB
24Wrong answer4ms548 KiB
subtask80/25
25Wrong answer46ms1476 KiB
26Accepted46ms1476 KiB
27Accepted46ms1476 KiB
28Accepted1ms500 KiB
29Wrong answer82ms1588 KiB
30Wrong answer109ms7732 KiB
31Wrong answer103ms7624 KiB
32Wrong answer93ms7732 KiB
33Wrong answer85ms6920 KiB
34Wrong answer86ms7104 KiB
35Wrong answer85ms6708 KiB
36Wrong answer104ms7732 KiB
37Wrong answer90ms7624 KiB
38Wrong answer83ms6708 KiB
39Wrong answer82ms1472 KiB
40Wrong answer59ms1476 KiB
41Wrong answer83ms6396 KiB
42Wrong answer52ms4148 KiB
43Wrong answer108ms7732 KiB
44Wrong answer97ms7620 KiB
45Wrong answer85ms7104 KiB
subtask90/25
46Wrong answer206ms15092 KiB
47Wrong answer181ms14036 KiB
48Wrong answer224ms15240 KiB
49Wrong answer170ms2612 KiB
50Wrong answer170ms2612 KiB
51Wrong answer168ms2768 KiB
52Wrong answer149ms11060 KiB
53Wrong answer170ms12600 KiB
54Wrong answer179ms13620 KiB
55Wrong answer112ms2612 KiB