其他分享
首页 > 其他分享> > cf - 1443C - The Delivery Dilemma

cf - 1443C - The Delivery Dilemma

作者:互联网

1443C - The Delivery Dilemma

// 排序加贪心
1.如果全用a数组送,a数组中的最大的数决定时间
2.同样全用b数组送,b数组之和决定时间。
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
typedef pair<int,int> PII;
typedef long long ll;
PII s[N];
ll sum[N];

int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        int n;
        cin >> n;
        sum[0] = 0;
        for(int i = 1;i <= n; i ++) cin >> s[i].first;
        for(int i = 1;i <= n; i ++) cin >> s[i].second;
        
        sort(s + 1,s + 1 + n);
        for(int i = 1; i <= n; i ++) sum[i] = sum[i - 1] + s[i].second;
        
        ll mx = 0x3f3f3f3f;
        mx = min(sum[n],1ll * s[n].first);
        
        for(int i = n - 1; i >= 1; i --)
        {
            ll t;
            t = max(0ll + s[i].first,sum[n] - sum[i]);
            mx = min(t,mx);
        }
        
        cout << mx << endl;
    }
}

标签:PII,Dilemma,int,sum,cf,Delivery,全用,数组,ll
来源: https://blog.csdn.net/weixin_45799361/article/details/114501396