zoukankan      html  css  js  c++  java
  • Codeforces Round #681 C

    Codeforces Round #681 C

    大意

    给定两个序列(a_{i})(b_{i}),从(a_{i})中选择一些元素,记为(t_{1},...,t_m)

    最小化(Sigma_{b_k otin{ti}}b_k + max(t_1,...,t_m))

    思路

    显然选择了一个 (t_i)后,所有小于它的(a_i)应该都选上。

    二分选择的值即可。

    代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    #define ll long long
    #define ull unsigned long long
    #define cint const int&
    #define Pi acos(-1)
    
    int t, n;
    ll sum[200200];
    ll tmp[200200];
    
    struct stu {
        ll a, b;
        bool operator < (const stu&ab) const {
            return a < ab.a;
        }
        void init() {
            cin >> a >> b;
        }
    }f[200200];
    
    ll cacu() {
        int key = lower_bound(tmp+1, tmp+1+n, 0) - tmp;
        return min(f[key].a, sum[n]-sum[key-1]);
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin >> t;
        while(t--) {
            cin >> n;
            for(int i=1; i<=n; i++) cin >> f[i].a;
            for(int i=1; i<=n; i++) cin >> f[i].b;
            sort(f+1, f+1+n);
            for(int i=1; i<=n; i++) sum[i] = sum[i-1] + f[i].b;
            for(int i=1; i<=n; i++) tmp[i] = f[i].a-sum[n]+sum[i];
            cout << cacu() << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    精简shell基础
    Centos7.4下安装Jumpserver 1.0.0(支持windows组件)
    二.Flask 学习模板
    一、Flask路由介绍
    web爬虫,BeautifulSoup
    web爬虫,requests请求
    django之Form组件补充
    中间件和Django缓存
    django之Form组件
    django from表单验证
  • 原文地址:https://www.cnblogs.com/ullio/p/13939174.html
Copyright © 2011-2022 走看看