Submission #55436

# Submission time Handle Problem Language Result Execution time Memory
55436 2018-07-07T10:07:55 Z Diuven Toilets (JOI16_toilets) C++11
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, inf=2e9;

ll n, m;

void NOPE(){
    cout<<-1;
    exit(0);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;

    ll mn=0, sum=0;

    char S[MX]; ll k;
    for(int i=1; i<=m; i++){
        cin>>(S+1)>>k;

        ll now=0, low=0;
        for(int i=1; S[i]!=0; i++){
            now+=(S[i]=='M' ? 1 : -1);
            low=min(low, now);
        }

        mn=min({mn, sum+low, sum+low+now*(k-1)});

        sum+=now*k;
    }

    if(sum>0) NOPE();
    cout<<min(0LL, sum-1-mn);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -