30pts求调
查看原帖
30pts求调
703022
wuyixiang楼主2023/8/7 11:22
#include <iostream>
#include <map>
#define int long long
using namespace std;
map<int,int>mp;
int n,k,x = 1e9,y,oq,d,ans;
char c;
signed main()
{
    cin >> n >> k;
    for(int i = 1;i <= n;i ++)
    {
        cin >> x >> c;
        if(c == 'L'){mp[y] --;y -= x;mp[y] ++;}
        else {mp[y + 1] ++;y += x;mp[y + 1] --;}
    }
    map<int,int>::iterator kk,kk2;
    for(kk = mp.begin();kk != mp.end();kk ++)
    {
        oq += (kk -> second);
        kk2 = kk;kk2 ++;
        if(oq >= k && kk2 != mp.end())ans += (kk2 -> first) - (kk -> first);
        d = (kk -> first);
    }
    cout << ans << endl;
}
2023/8/7 11:22
加载中...