http://acm.hdu.edu.cn/showproblem.php?pid=4882

就是CF的比赛,根据时间的推迟会相应的扣掉题目的分数,每个任务有e,k,e表示完成需要时间,k表示完成后消耗罚时,问说最少扣几分。


k大的尽量早完成,t小的尽量早完成,所以t / k小的尽量早完成,排序即可

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))

typedef __int64 LL;
#define l first
#define r second

struct node{
    int t,k;
}s[1000005];
bool cmp(node a,node b)
{
    return a.t*b.k < a.k*b.t;
}
int main(){
    int n;
    while(~RD(n)){
        for(int i = 0;i < n;++i)
            RD(s[i].t);
        for(int i = 0;i < n;++i){
            RD(s[i].k);
        }
        sort(s,s+n,cmp);
        LL ans = 0,t = 0;
        for(int i = 0;i < n;++i){
            t += (LL)s[i].t;
            ans += (LL)s[i].k*t;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


相关文章:

  • 2021-09-16
  • 2021-06-25
  • 2022-03-08
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-01-11
  • 2021-06-25
  • 2021-10-17
  • 2021-09-04
相关资源
相似解决方案