湖大训练赛第十场 Electricity

Electricity
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:262144KB
Total submit users: 22, Accepted users: 16
Problem 12909 : No special judgement
Problem description


Input

The first line of input file contains two integer numbers n and m — the number of power strips of the first and the second type (0 ≤ n,m ≤ 100000).

The second line contains n integer numbers ai— the number of sockets on the power strips of the first type (1 ≤ ai≤ 1000).

The second line contains m integer numbers bi— the number of sockets on the power strips of the second type (1 ≤ bi≤ 1000).


Output

Output the maximum number of computers that can be connected to the power network.


Sample Input
3 2
3 2 1
2 3

2 3
2 2
2 3 1
Sample Output
5

5

题意:实验室只有一个接口,还是A类型的。学生每台电脑的接头都是A类型的。肯定只能接一个用。唉。

莫慌。我们还有两座类型的插座分别有N,M个。A类型插头是A,插板上有许多个B类型接口。B类型的插头是B,插板上有许多A类型接口。输入N,M,接下来N个数是每个A类型插板上有多少个B型接口。接下来M个数是每个B类型插板上有多少个A型接口。问实验室最多能接多少台电脑。ORz。。。跟我们实验室串联好像啊。。。

题解:按平时习惯我们当然是喜欢接口越多的插板。所以我们分别把两种类型插座按从大到小排序。如果没有A类型插座当然只有1台电脑可以接电了。否则先接最多接口的A类型,然后插满!!!B,如果还有B没插到,继续插个A,继续插B...直到A没有了或者B没有了。OK.Accpet.看着就有点小激动呢。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#define LL __int64
#define EPS 1e-8
using namespace std;
int cmp(int x,int y)
{
	return x>y;
}
int cmp1(int x,int y)
{
	return x>y;
}
int a[100010],b[100010];
int main()
{
	int n,m,i;
	while (~scanf("%d%d",&n,&m))
	{
		for (i=0;i<n;i++)
			scanf("%d",&a[i]);
		for (i=0;i<m;i++)
			scanf("%d",&b[i]);
		if (n==0) 
		{
			puts("1");
			continue;
		}
		sort(a,a+n,cmp);
		sort(b,b+m,cmp1);
		int a1=0,b1=0;
		int ans=1;
		while (1)
		{
			ans--;
			for (i=0;i<a[a1];i++)
			{
				ans+=b[b1];
				b1++;
				if (b1==m) break;
			}
			a1++;
			if (a1==n || b1==m) break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值