求助 这两段代码有啥区别啊
查看原帖
求助 这两段代码有啥区别啊
93465
Celestial_Scarlet楼主2021/9/25 22:12
// WA 20pts
int calc(int x) {
    //...
    std::sort(a+1,a+m+1);
    int s=0;
    for (int i=1; i<=n; ++i) {
        s+=a[m-i+1];
        if (s>=k) return 1;
    }
    return 0;
}
// AC 100pts
inline int cmp(int x,int y) { return (x>y); }
int calc(int x) {
    //...
    std::sort(a+1,a+m+1,cmp);
    int s=0;
    for (int i=1; i<=n; ++i) {
        s+=a[i];
        if (s>=k) return 1;
    }
    return 0;
}

k 为 int 且 1k1071\le k\le 10^7
a 中元素为 int 且 0ai1090\le a_i\le 10^9

没看出来第一份代码出啥锅了 /yun

2021/9/25 22:12
加载中...