• CF1379C.Choosing Flowers(二分)


    给出m种花,对于每一种花,购买第一束可以带来ai的开心值,之后买第二束、第三束会增加bi...你可以购买n种花,询问怎么设计购买方案,使得总开心值最大。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=2e5+100;
    typedef long long ll;
    int n,m;
    struct node {
        ll a,b;
        bool operator < (const node &r) const {
            return a>r.a;
        }
    }Node[maxn];
    ll pre[maxn];
    int main () {
        int t;
        scanf("%d",&t);
        while (t--) {
            scanf("%d%d",&n,&m);
            for (int i=1;i<=m;i++) {
                scanf("%d%d",&Node[i].a,&Node[i].b);
            }
            sort(Node+1,Node+m+1);
            for (int i=1;i<=m;i++) pre[i]=pre[i-1]+Node[i].a;
            ll ans=0;
            for (int i=1;i<=m;i++) {
                int l=1,r=m;
                int tt=0;
                while (l<=r) {
                    int mid=(l+r)>>1;
                    if (Node[mid].a>=Node[i].b)
                        l=mid+1,tt=mid;
                    else
                        r=mid-1;
                }
                if (tt>=n)
                    ans=max(ans,pre[n]);
                else {
                    if (tt>=i)
                        ans=max(ans,pre[tt]+Node[i].b*(n-tt));
                    else
                        ans=max(ans,pre[tt]+Node[i].a+Node[i].b*(n-tt-1));
                }
            }
            printf("%lld
    ",ans);
        }
    }
  • 相关阅读:
    NSPredicate
    label 下划线加自动换行
    【搬运】快速增加文档注释
    NSSortDescriptor 数组排序
    【搬运】打开模拟器沙盒目录
    NSTimer 详解
    Android打开外部DB文件
    图片压缩与缓存
    StartService与BindService
    Android发送通知栏通知
  • 原文地址:https://www.cnblogs.com/zhanglichen/p/13343987.html
Copyright © 2020-2023  润新知