Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define MAXN 131072*8
- using namespace std;
- vector< pair<int,int> >v[MAXN];
- string s;
- int cnt=1,used[MAXN],arr[MAXN],m[MAXN];
- int main()
- {
- int x,n,i,j,tek=0,id=0,ans=0;
- cin>>n;
- for(i=0;i<n;i++)
- {
- cin>>s;
- x=0;
- for(j=1;j<s.size();j++)
- {
- x*=10;
- x+=s[j]-'0';
- }
- if(!used[x])
- {
- used[x]=cnt;
- v[cnt++].push_back({s[0]=='s' ? 1 : -1 ,i+1});
- }
- else
- {
- v[used[x]].push_back({s[0]=='s' ? 1 : -1 ,i+1});
- }
- }
- memset(used,0,sizeof(used));
- for(i=1;i<cnt;i++)
- {
- tek=0;
- //cout<<i<<" : ";
- for(j=0;j<v[i].size();j++)
- {
- //cout<<v[i][j].second<<" ";
- tek+=v[i][j].first;
- m[i]=min(tek,m[i]);
- }//cout<<endl;
- if(tek!=0)used[i]=true;
- }
- for(i=1;i<cnt;i++)
- {
- if(used[i])continue;
- tek=0;
- for(j=0;j<v[i].size();j++)
- {
- tek+=v[i][j].first;
- if(tek==m[i])
- {
- arr[v[i][j].second]++;
- if(j==v[i].size()-1)
- {
- arr[n+2]--;
- arr[0]++;
- arr[v[i][0].second]--;
- }else arr[v[i][j+1].second]--;
- }
- }
- }
- tek=0;
- for(i=0;i<=n;i++)
- {
- tek+=arr[i];
- if(tek>ans)
- {
- ans=tek;
- id=i;
- }
- }
- if(id+1==n+1)
- id=1;
- cout<<id+1<<" "<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement