# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155386 | TadijaSebez | Toilets (JOI16_toilets) | C++11 | 39 ms | 4844 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 pb push_back
const int N=200050;
char s[N];
int main()
{
ll n;
int m;
scanf("%lld %i",&n,&m);
vector<pair<ll,pair<ll,ll>>> v;
ll all=0;
for(int i=1;i<=m;i++)
{
scanf("%s",s+1);
int len=strlen(s+1);
ll k;
scanf("%lld",&k);
ll mx=0,balance=0;
for(int j=len;j>=1;j--)
{
balance+=(s[j]=='F'?-1:1);
mx=max(mx,balance);
if(s[j]=='F') all-=k;
else all+=k;
}
v.pb({k,{mx,balance}});
//printf("%lld %lld\n",mx,balance);
}
if(all>0) return 0*printf("-1\n");
ll sum=0,ans=0;
while(v.size())
{
ll k,mx,b;
//tie(k,mx,b)=v.back();
k=v.back().first;
mx=v.back().second.first;
b=v.back().second.second;
v.pop_back();
if(b>0) ans=max(ans,mx+sum+b*(k-1));
else ans=max(ans,mx+sum);
sum+=k*b;
}
printf("%lld\n",max((ll)0,ans-1));
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... |