1 solutions

  • 0
    @ 2026-11-11 10:52:10
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int N=2e5+10;
    typedef pair<LL,char> PLC;
    PLC q[N];
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>q[i].first>>q[i].second;
    	}
    	int l=1,r=n;
    	LL ans=0;
    	while(l<=r)
    	{
    		//cout<<l<<" "<<r;
    		LL minv=min(q[l].first,q[r].first);
    		if(q[l].second!=q[r].second)
    		{
    			ans+=minv;
    		}
    		q[l].first-=minv;
    		q[r].first-=minv;
    		if(q[l].first<=0) l++;
    		if(q[r].first<=0) r--;
    	}
    	cout<<ans;
    	return 0;
    } 
    
    • 1

    Information

    ID
    3615
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    9
    Accepted
    2
    Uploaded By