• 题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少花多少时间能使午餐到家.

  • 题解:我们可以用结构体记录每份午餐的外卖所需时间和自己拿的时间,然后贪心,对于某一份午餐,如果我们选择用外卖送,那么所有\(a_i\)比这个外卖时间小的在这个外卖送到时必然都能送到,所以我们可以对外卖时间进行排序,然后枚举每份午餐,每次让枚举位置和之前的位置用外卖送,枚举位置之后的自己跑去买,所以我们可以用后缀和记录自己买的时间,在外卖送的时间和自己买的时间之和之间取个最小值维护答案即可.

  • 代码:

    struct misaka{
    ll a,b;
    bool operator < (const misaka & mikoto) const{
    if(a!=mikoto.a) return a<mikoto.a;
    return b<mikoto.b;
    }
    }e[N]; int t;
    int n;
    ll cnt[N]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
    cin>>n; for(int i=1;i<=n;++i) cin>>e[i].a;
    for(int i=1;i<=n;++i) cin>>e[i].b; sort(e+1,e+1+n); for(int i=n;i>=1;--i) cnt[i]=cnt[i+1]+e[i].b; ll ans=1e18; for(int i=0;i<=n;++i){
    ans=min(ans,max(e[i].a,cnt[i+1]));
    }
    for(int i=1;i<=n;++i) cnt[i]=0;
    cout<<ans<<'\n'; } return 0;
    }

Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)的更多相关文章

  1. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】

    比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...

  2. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  3. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D. Extreme Subtraction (贪心)

    题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解: ...

  4. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) B. Saving the City (贪心,模拟)

    题意:给你一个\(01\)串,需要将所有的\(1\)给炸掉,每次炸都可以将一整个\(1\)的联通块炸掉,每炸一次消耗\(a\),可以将\(0\)转化为\(1\),消耗\(b\),问将所有\(1\)都炸 ...

  5. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) A. Kids Seating (规律)

    题意:给你一个正整数\(n\),在\([1,4n]\)中找出\(n\)个数,使得这\(n\)个数中的任意两个数不互质且不能两两整除. 题解:这题我是找的规律,从\(4n\)开始,往前取\(n\)个偶数 ...

  6. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  7. Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...

  8. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

    A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...

  9. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring

    C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandar ...

随机推荐

  1. 【Problems】Could not set property 'id' of 'xxx' with value '' Cause argument type mismatch

    一个问题:向comment表添加记录时,报错, 无法设置值. reflection.ReflectionException: Could not set property 'id' of 'class ...

  2. 【Linux】saltstack 安装及简单使用

    准备三台server,一台为master(10.96.20.113),另两台为minion(10.96.20.117,10.96.20.118) 主机名(master.minion1.minion2) ...

  3. kubernets集群的安全防护(下)

    一   集群角色以及集群角色绑定 1.1  前面我们提到过角色以及角色绑定,那么现在为什么会出现集群级别的角色以及角色绑定,作用有如下所示 我们如果需要在所有的命名的空间创建某个角色或者角色绑定的时候 ...

  4. oracle_fdw的安装和使用

    1.下载instant oracle client 下载网址:https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html ...

  5. C#使用struct直接转换下位机数据

    编写上位机与下位机通信的时候,涉及到协议的转换,比较多会使用到二进制.传统的方法,是将数据整体获取到byte数组中,然后逐字节对数据进行解析.这样操作工作量比较大,对于较长数据段更容易计算位置出错. ...

  6. winform 扫码识别二维码

    因为公司业务需求,需要在Windows系统下调用摄像头识别二维码需求,就有了这个功能. 我根据网上网友提供的一些资料,自己整合应用到项目中,效果还不错(就是感觉像素不是太好) 现在将调用摄像头+识别二 ...

  7. CentOS 镜像下载地址

    CentOS镜像地址:http://isoredirect.centos.org/altarch/7/isos/i386/

  8. 主题模型(Topic)

    消息队列 RocketMQ - 打造金融级消息服务 - 阿里云 https://www.aliyun.com/product/rocketmq 主题模型(Topic) 发布/订阅(Pub/Sub) 一 ...

  9. 美团配送A/B评估体系建设与实践

    https://mp.weixin.qq.com/s/v3Fvp6Hed7ZGoE8FGlGMvQ

  10. Page not found (404) 不被Django的exception中间件捕捉 中间件

    Using the URLconf defined in config.urls, Django tried these URL patterns, in this order: