# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105715 | Pro_ktmr | Toilets (JOI16_toilets) | C++14 | 120 ms | 5852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)
LL N,M;
string S[100000];
LL K[100000];
LL ans = 0;
int main(){
cin >> N >> M;
LL male2 = 0;
for(int i=0; i<M; i++){
cin >> S[i] >> K[i];
for(int j=0; j<S[i].size(); j++){
if(S[i][j] == 'M') male2 += K[i];
}
reverse(S[i].begin(), S[i].end());
}
reverse(S, S+M);
reverse(K, K+M);
if(male2 > N){
cout << -1 << endl;
return 0;
}
LL sumMale = 0;
LL sum = 0;
for(int i=0; i<M; i++){
LL male = 0;
for(LL j=0; j<S[i].size(); j++){
if(S[i][j] == 'M'){
ans = max(ans, 2*(male+sumMale) - (j+sum));
male++;
}
}
sumMale += male * (K[i] - 1);
sum += (LL)S[i].size() * (K[i] - 1);
male = 0;
for(LL j=0; j<S[i].size(); j++){
if(S[i][j] == 'M'){
ans = max(ans, 2*(male+sumMale) - (j+sum));
male++;
}
}
sumMale += male;
sum += (LL)S[i].size();
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |