1 条题解

  • 0
    @ 2025-2-14 21:11:41

    C++ :

    #include<stdio.h>
    #include<algorithm>
    using namespace  std;
    struct store
    {
     int x;
     int feeds;
     int cents;
    }a[101];
    bool cmp(store al,store a2)
    {
     return al.cents<a2.cents;
    }
    int main()
    {
         int T,i,K,E,N,money;
         scanf("%d",&T);
         while(T--)
         {
              if(scanf("%d %d %d",&K,&E,&N)==EOF) return 0;
              for(i=0;i<N;++i)
              {
               scanf("%d %d %d",&a[i].x,&a[i].feeds,&a[i].cents);
               a[i].cents+=E-a[i].x;//单位点购买one feed ,费用值(运至E)
              }
              sort(a,a+N,cmp);
              money=0;
              for(i=0;i<N;i++)
              {
                   if(a[i].feeds<=K)//购买feeds
                   {
                    money +=a[i].feeds*a[i].cents;
                    K -=a[i].feeds;
                   }
                   else {money +=K*a[i].cents; break;}
              }
              printf("%d\n",money);
          }return 0;
    }
    
    
    • 1

    信息

    ID
    699
    时间
    3000ms
    内存
    64MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者