跳到正文

题解

题解:P12733 磨合

Ex_cry_world约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P12733

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N=2e6+10;

int n,q;
int a[N];

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);/* 临价交换可得大的排前一定比小的排前优) */
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            a[j]+=a[j-1];/* 快速求前缀 */
        }
    }
    for(int i=1;i<=q;i++){
        int t;
        cin>>t;
        cout<<upper_bound(a+1,a+1+n,t)-a-1<<"\n";/* 二分最多能完成的任务 */
    }
    return 0;
}
原文