11517 | 2024-10-16 19:04:39 | chucknorris | 2015. november | cpp17 | Accepted | 225ms | 6768 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;
}
6
Expected output:6
Checker output:ok 1 number(s): "6"
1997031047
Expected output:1997031047
Checker output:ok 1 number(s): "1997031047"
1994299081
Expected output:1994299081
Checker output:ok 1 number(s): "1994299081"
1992381668
Expected output:1992381668
Checker output:ok 1 number(s): "1992381668"
1999133839
Expected output:1999133839
Checker output:ok 1 number(s): "1999133839"
1997221669
Expected output:1997221669
Checker output:ok 1 number(s): "1997221669"
1997415382
Expected output:1997415382
Checker output:ok 1 number(s): "1997415382"
1995739072
Expected output:1995739072
Checker output:ok 1 number(s): "1995739072"
1999149840
Expected output:1999149840
Checker output:ok 1 number(s): "1999149840"
1997981017
Expected output:1997981017
Checker output:ok 1 number(s): "1997981017"
1999532360
Expected output:1999532360
Checker output:ok 1 number(s): "1999532360"
1997082343
Expected output:1997082343
Checker output:ok 1 number(s): "1997082343"
1999526630
Expected output:1999526630
Checker output:ok 1 number(s): "1999526630"
1998589395
Expected output:1998589395
Checker output:ok 1 number(s): "1998589395"
1997318421
Expected output:1997318421
Checker output:ok 1 number(s): "1997318421"
1979224845
Expected output:1979224845
Checker output:ok 1 number(s): "1979224845"
1991997984
Expected output:1991997984
Checker output:ok 1 number(s): "1991997984"
1999545973
Expected output:1999545973
Checker output:ok 1 number(s): "1999545973"
1985759896
Expected output:1985759896
Checker output:ok 1 number(s): "1985759896"
1998064428
Expected output:1998064428
Checker output:ok 1 number(s): "1998064428"
1995292369
Expected output:1995292369
Checker output:ok 1 number(s): "1995292369"
1996368765
Expected output:1996368765
Checker output:ok 1 number(s): "1996368765"
1994572365
Expected output:1994572365
Checker output:ok 1 number(s): "1994572365"
1998851953
Expected output:1998851953
Checker output:ok 1 number(s): "1998851953"
1994600921
Expected output:1994600921
Checker output:ok 1 number(s): "1994600921"
1999348488
Expected output:1999348488
Checker output:ok 1 number(s): "1999348488"
1998414563
Expected output:1998414563
Checker output:ok 1 number(s): "1998414563"
1996478400
Expected output:1996478400
Checker output:ok 1 number(s): "1996478400"
1995753429
Expected output:1995753429
Checker output:ok 1 number(s): "1995753429"
1984640026
Expected output:1984640026
Checker output:ok 1 number(s): "1984640026"
1994383789
Expected output:1994383789
Checker output:ok 1 number(s): "1994383789"