zoukankan      html  css  js  c++  java
  • LOJ#6035. 「雅礼集训 2017 Day4」洗衣服 题解

    题目链接

    首先把两个过程分别贪心,然后对应匹配一下即可。

    (O(l log n).)

    code :

    #include <bits/stdc++.h>
    #define LL long long
    using namespace std;
    template <typename T> void read(T &x){
    	x = 0; char ch = getchar();
    	while (!isdigit(ch)) ch = getchar();
    	while (isdigit(ch)) x = x * 10 + ch - '0',ch = getchar();
    }
    const int N = 1000050;
    int n,m,k; LL a[N],b[N],ta[N],tb[N];
    struct Node{
    	int x; LL v;
    	Node(int xx=0,LL vv=0){ x=xx,v=vv; }
    	inline bool operator < (const Node w) const{ return v > w.v; } 
    };
    priority_queue<Node>H;
    inline void work(int n,LL *a,LL *t){
    	static LL tt[N];
    	int len = 0,i; Node tmp;
    	while (!H.empty()) H.pop();
    	for (i = 1; i <= n; ++i) H.push(Node(i,a[i])),tt[i] = a[i];
    	while (len < k){
    		tmp = H.top(); H.pop(); t[++len] = tmp.v;
    		i = tmp.x; tt[i] += a[i]; H.push(Node(i,tt[i])); 
    	}
    }
    int main(){
    	int i;
    	read(k),read(n),read(m);
    	for (i = 1; i <= n; ++i) read(a[i]);
    	for (i = 1; i <= m; ++i) read(b[i]);
    	work(n,a,ta); work(m,b,tb);
    	LL ans = 0;
    	for (i = 1; i <= k; ++i) ans = max(ans,ta[i] + tb[k+1-i]);
    	cout << ans << '
    ';
    	return 0;
    }
    
  • 相关阅读:
    OpenGL入门1.3:着色器 GLSL
    OpenGL入门1.2:渲染管线简介,画三角形
    C++回调,函数指针
    JavaScript 比较和逻辑运算符
    JS 运算符
    JS 函数
    JS 对象
    JS 数据类型
    JS 变量
    JS 注释
  • 原文地址:https://www.cnblogs.com/s-r-f/p/13651964.html
Copyright © 2011-2022 走看看