#40226: 只要用return就行了


yp11251273@yphs.tp.edu.tw (704-31張鈞勉)

學校 : 臺北市私立延平高級中學
編號 : 239174
來源 : [203.72.178.1]
最後登入時間 :
2024-05-07 17:49:28
b159. NOIP2007 2.纪念品分组 -- NOIP2007普及組 | From: [203.72.178.1] | 發表日期 : 2024-04-30 17:44

#include<bits/stdc++.h>
using namespace std;
int main(){
    int w,n;
    while(cin>>w>>n)
    {
        int a[n];
        for(int i=0; i<=n; i++) cin>>a[i];
        sort(a,a+n);
        int l=0, r=n-1, cnt=n;
        while(l<r)
        {
            if(a[l]+a[r]<=w) cnt--, l++, r--;
            else r--;
        }
        cout<<cnt<<'\n';
    }
    return 0;
}只要用return就行了

 
ZeroJudge Forum