there is the center of happiness!
查看原帖
there is the center of happiness!
544446
Demon_master楼主2021/8/6 20:13
#include<bits/stdc++.h>
using namespace std;
int a[62];
int main(){
    int V,M;
    scanf("%d%d",&V,&M);
    for(int i=0;i<M;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+M);
    int v=V;
    for(int i=M-1;i>=0;i--){
        V-=a[i];
        if(V<0) V+=a[i];
    }
    for(int i=0;i<M;i++){
        v-=a[i];
        if(v<0) v+=a[i];
    }
    cout<<(v>=V ? V:v);
    return 0;
}
2021/8/6 20:13
加载中...