1 条题解

  • 0
    @ 2025-10-8 17:01:39

    by hansang:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    typedef long long LL;
    struct node{LL w, s;} a[N];
    bool cmp(node n1, node n2){
    	return (n1.w-n2.s)<(n2.w-n1.s);
    }
    int main(){
    	int n; scanf("%d", &n);
    	for(int i=1; i<=n; i++){
    		scanf("%lld%lld", &a[i].w, &a[i].s);
    	}
    	sort(a+1, a+n+1, cmp);
    	LL sum=0, ans=-1e9;
    	for(int i=1; i<=n; i++){
    		ans=max(ans, sum-a[i].s);
    		sum+=a[i].w;
    	}
    	printf("%lld\n", ans);
    	return 0;
    }
    • 1

    USACO(28)贪心进阶2:奶牛杂技[Cow Acrobats&#44; 2005 Nov]

    信息

    ID
    2625
    时间
    1000ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    9
    已通过
    6
    上传者