贴下第二题代码:
#include<iostream>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;

int Get_Num(priority_queue<int> Prac,int sum,int total)
{
    int ans = 0;
    while(total < sum)
    {
        sum -= Prac.top();
        Prac.pop();
        ans++;
    }
    return ans;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,m;
        cin>>n>>m;
        int sum = 0;
        priority_queue<int> Prac;
        for(auto i = 0;i < n;i++)
        {
            int pi;
            cin>>pi;
            if(sum+pi <= m)
            {
                cout<<0<<" ";
                sum += pi;
                Prac.push(pi);
                
            }else
            {
                int total = m - pi;
                cout<<Get_Num(Prac,sum,total)<<' ';
                sum+=pi;
                Prac.push(pi);
            }
        }
        cout<<endl;
    }
    return 0;
}
有人能帮我看一下我的第一题嘛:
#include<string>
#include<vector>
#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string S;
    cin>>S;
    vector<int> lr(n,0);
    vector<int> cnt(n,0);
    for(auto i = 0 ; i < n; i ++)
    {
        if(i == 0)
        {
            if(S[i] == 'O')
            {
                cnt[i] = 0;
            }else
            {
                int j = i+1;
                while(S[j] != 'O') j++;
                lr[i] = 1;
                cnt[i] = j-i;
            }
        }
        else if(i == n-1)
        {
            if(S[i] == 'O')
            {
                cnt[i] = 0;
            }
            else 
            {
                cnt[i] = cnt[i-1]+1;
            }
        }
        else
        {
            if(S[i] == 'O')
            {
                lr[i]=0;
                cnt[i] = 0;
            }else if(lr[i-1] == 1)
            {
                lr[i] = 1;
                cnt[i] = cnt[i-1] -1;
            }else if(lr[i-1] == 0)
            {
                if(S[i+1] == 'O')
                {
                    lr[i] = 1;
                }
                else
                {
                    lr[i] = -1;

                }
                cnt[i] = 1;
            }
            else
            {
                bool right = false;
                for(auto j = cnt[i-1]-1;j <= cnt[i-1]+1;j++)
                {
                    if(S[i+j] == 'O')
                    {
                        right = true;
                        cnt[i] = j;
                    }
                }
                if(right == true)
                {
                    lr[i] = 1;
                }
                else 
                {
                    lr[i] = -1;
                    cnt[i] = cnt[i-1]+1;
                }
            }
        }
    }
    for(auto I:cnt)
    {
        cout<<I<<' ';
    }
    
    return 0;

第二题全过了,第一题只过了10%