115172024-10-16 19:04:39chucknorris2015. novembercpp17Accepted 225ms6768 KiB
#include <bits/stdc++.h>
#define INF 1000000007

using namespace std;

int N, K, poz;
vector<int>bal, jobb;

int main(){
    cin >> N >> K;
    poz = 0;
    for(int i = 1; i <= N; i++){
        int lepes;
        char irany;
        cin >> lepes >> irany;
        if(irany == 'R'){
            bal.push_back(poz + 1); jobb.push_back(poz + lepes);
            poz = poz + lepes;
        }
        else{
            bal.push_back(poz - lepes); jobb.push_back(poz - 1);
            poz = poz - lepes;
        }
    }

    sort(bal.begin(), bal.end());
    sort(jobb.begin(), jobb.end());

    long long ans = 0;
    int cnt = 0, i = 0, j = 0, start = 1e9;

    while(i < N or j < N){
        if(i < N and bal[i] <= jobb[j]){
            cnt = cnt + 1;
            if(cnt == K) start = bal[i];
            i = i + 1;
        }
        else{
            if(cnt == K and start != INF) {
                ans = ans + (jobb[j] - start + 1);
                start = INF;
            }
            cnt = cnt - 1; j = j + 1;
        }
    }

    cout << ans;
    return 0;
}
1 - Accepted
Memory: 332KiB
Time: 1ms

Program's output:
6
Expected output:
6
Checker output:
ok 1 number(s): "6"

2 - Accepted
Memory: 3676KiB
Time: 122ms

Program's output:
1997031047
Expected output:
1997031047
Checker output:
ok 1 number(s): "1997031047"

3 - Accepted
Memory: 2920KiB
Time: 100ms

Program's output:
1994299081
Expected output:
1994299081
Checker output:
ok 1 number(s): "1994299081"

4 - Accepted
Memory: 580KiB
Time: 9ms

Program's output:
1992381668
Expected output:
1992381668
Checker output:
ok 1 number(s): "1992381668"

5 - Accepted
Memory: 3560KiB
Time: 108ms

Program's output:
1999133839
Expected output:
1999133839
Checker output:
ok 1 number(s): "1999133839"

6 - Accepted
Memory: 3684KiB
Time: 122ms

Program's output:
1997221669
Expected output:
1997221669
Checker output:
ok 1 number(s): "1997221669"

7 - Accepted
Memory: 2160KiB
Time: 71ms

Program's output:
1997415382
Expected output:
1997415382
Checker output:
ok 1 number(s): "1997415382"

8 - Accepted
Memory: 4448KiB
Time: 160ms

Program's output:
1995739072
Expected output:
1995739072
Checker output:
ok 1 number(s): "1995739072"

9 - Accepted
Memory: 4188KiB
Time: 146ms

Program's output:
1999149840
Expected output:
1999149840
Checker output:
ok 1 number(s): "1999149840"

10 - Accepted
Memory: 3928KiB
Time: 135ms

Program's output:
1997981017
Expected output:
1997981017
Checker output:
ok 1 number(s): "1997981017"

11 - Accepted
Memory: 6752KiB
Time: 225ms

Program's output:
1999532360
Expected output:
1999532360
Checker output:
ok 1 number(s): "1999532360"

12 - Accepted
Memory: 6768KiB
Time: 211ms

Program's output:
1997082343
Expected output:
1997082343
Checker output:
ok 1 number(s): "1997082343"

13 - Accepted
Memory: 5360KiB
Time: 196ms

Program's output:
1999526630
Expected output:
1999526630
Checker output:
ok 1 number(s): "1999526630"

14 - Accepted
Memory: 4956KiB
Time: 182ms

Program's output:
1998589395
Expected output:
1998589395
Checker output:
ok 1 number(s): "1998589395"

15 - Accepted
Memory: 1516KiB
Time: 41ms

Program's output:
1997318421
Expected output:
1997318421
Checker output:
ok 1 number(s): "1997318421"

16 - Accepted
Memory: 1264KiB
Time: 28ms

Program's output:
1979224845
Expected output:
1979224845
Checker output:
ok 1 number(s): "1979224845"

17 - Accepted
Memory: 2032KiB
Time: 61ms

Program's output:
1991997984
Expected output:
1991997984
Checker output:
ok 1 number(s): "1991997984"

18 - Accepted
Memory: 4956KiB
Time: 177ms

Program's output:
1999545973
Expected output:
1999545973
Checker output:
ok 1 number(s): "1999545973"

19 - Accepted
Memory: 1392KiB
Time: 35ms

Program's output:
1985759896
Expected output:
1985759896
Checker output:
ok 1 number(s): "1985759896"

20 - Accepted
Memory: 1092KiB
Time: 23ms

Program's output:
1998064428
Expected output:
1998064428
Checker output:
ok 1 number(s): "1998064428"

21 - Accepted
Memory: 3672KiB
Time: 115ms

Program's output:
1995292369
Expected output:
1995292369
Checker output:
ok 1 number(s): "1995292369"

22 - Accepted
Memory: 3672KiB
Time: 129ms

Program's output:
1996368765
Expected output:
1996368765
Checker output:
ok 1 number(s): "1996368765"

23 - Accepted
Memory: 3676KiB
Time: 116ms

Program's output:
1994572365
Expected output:
1994572365
Checker output:
ok 1 number(s): "1994572365"

24 - Accepted
Memory: 3676KiB
Time: 104ms

Program's output:
1998851953
Expected output:
1998851953
Checker output:
ok 1 number(s): "1998851953"

25 - Accepted
Memory: 2652KiB
Time: 90ms

Program's output:
1994600921
Expected output:
1994600921
Checker output:
ok 1 number(s): "1994600921"

26 - Accepted
Memory: 4944KiB
Time: 180ms

Program's output:
1999348488
Expected output:
1999348488
Checker output:
ok 1 number(s): "1999348488"

27 - Accepted
Memory: 2908KiB
Time: 96ms

Program's output:
1998414563
Expected output:
1998414563
Checker output:
ok 1 number(s): "1998414563"

28 - Accepted
Memory: 2480KiB
Time: 83ms

Program's output:
1996478400
Expected output:
1996478400
Checker output:
ok 1 number(s): "1996478400"

29 - Accepted
Memory: 4956KiB
Time: 173ms

Program's output:
1995753429
Expected output:
1995753429
Checker output:
ok 1 number(s): "1995753429"

30 - Accepted
Memory: 2020KiB
Time: 59ms

Program's output:
1984640026
Expected output:
1984640026
Checker output:
ok 1 number(s): "1984640026"

31 - Accepted
Memory: 4180KiB
Time: 148ms

Program's output:
1994383789
Expected output:
1994383789
Checker output:
ok 1 number(s): "1994383789"