2 条题解

  • 0
    @ 2025-10-8 17:05:17

    by hansang(scy20250226修改):

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int N=1e4+10;
    struct node{int x, f; LL c;} a[N]; 
    bool operator<(node n1, node n2){return n1.c > n2.c;}
    int main()
    {
        int K, e, n; scanf("%d%d%d", &K, &e, &n);
        priority_queue<node> Q;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%lld", &a[i].x, &a[i].f, &a[i].c);a[i].c += e - a[i].x;
            Q.push(a[i]);
        }
        LL ans=0; 
        while(K>0)
        {
            node no=Q.top();
            if(no.f <= K)
            {
                K -= no.f;
                ans += no.f * no.c;
                Q.pop();
            }
            else
            {
                ans += K * no.c;
                break;
            }
        }
        printf("%lld\n", ans);
        return 0;
    }
    
    • 0
      @ 2025-10-8 17:05:06

      by hansang(scy20250226修改):

      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      const int N=1e4+10;
      struct node{int x, f; LL c;} a[N]; 
      bool operator<(node n1, node n2){return n1.c>n2.c;}
      int main()
      {
      	int K, e, n; scanf("%d%d%d", &K, &e, &n);
      	priority_queue<node> Q;
      	for(int i=1; i<=n; i++)
      	{
      		scanf("%d%d%lld", &a[i].x, &a[i].f, &a[i].c);a[i].c+=e-a[i].x;
      		Q.push(a[i]);
      	}
      	LL ans=0; 
      	while(K>0)
      	{
      		node no=Q.top();
      		if(no.f<=K)
      		{
      			K-=no.f;
      			ans+=no.f*no.c;
      			Q.pop();
      		}
      		else
      		{
      			ans+=K*no.c;
      			break;
      		}
      	}
      	printf("%lld\n", ans);
      	return 0;
      }
      • 1

      *【贪心】购买饲料[USACO10JAN] Buying Feed II S

      信息

      ID
      3685
      时间
      1000ms
      内存
      128MiB
      难度
      3
      标签
      递交数
      64
      已通过
      33
      上传者