1 条题解

  • 0
    @ 2025-10-10 19:24:13

    C++ :

    #include<iostream>
    #include<queue>
    #include<vector>
    #include<algorithm>
    using  namespace  std;
    const int N=30010;
    int  n,m; 
    int a[N],b[N];
    int  main()
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int j=0;j<m;j++)cin>>b[j];
        sort(b,b+m);
        priority_queue<int> left;
        priority_queue<int,vector<int>,greater<int>> right;
        
        int i=0,j=0;  
        while(i<n || j<m)  
        {
          while(j<m && b[j]==i)
            {
               cout<<right.top()<<endl;
               left.push(right.top());
               right.pop();
               j++;
                
            }
            int x=a[i];
            if(left.empty()||x>=right.top()) right.push(x);
            else
            {
                left.push(x);
                right.push(left.top());
                left.pop();
            }
            i++;
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    678
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者