이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fs first
#define sc second
ll N,M;
vector<pair<string,ll>> v;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>N>>M;
ll sum = 0,ans = 0;
for(ll i = 0;i<M;i++){
string s;
ll t;
cin>>s>>t;
reverse(s.begin(),s.end());
v.push_back(make_pair(s,t));
}
reverse(v.begin(),v.end());
for(auto [s,t] : v){
ll ts = 0,tbig = -1e18;
for(auto &i:s){
if(i == 'F'){
ts--;
tbig = max(tbig,ts);
}
else ts++;
}
ans = max(ans,sum+tbig);
sum += ts*(t-1);
ans = max(ans,sum+tbig);
sum += ts;
}
if(sum>0)cout<<"-1\n";
else cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |