Codeforces Round #680 A-B

在这里插入图片描述
在这里插入图片描述

题意

给你两个集合( a , b ),每个集合都有 n 个元素,再给一个 x ,问你能不能通过改变 b 集合的元素顺序使得任意 i ,满足 ai + bi <= x

思路

a 从小到大排序,b 从大到小排序,然后看对应位置 ai + bi 与 x 关系,都满足就Yes , 否则No.

代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e7+10;
const int mod=10007;
int a[110],b[110];
bool cmp(int x,int y)
{
	return x>y;
} 
int main()
{
	ios::sync_with_stdio(false);
	int t,n,x;
	cin>>t;
	while(t--)
	{
		cin>>n>>x;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++) cin>>b[i];
		sort(a+1,a+n+1);
		sort(b+1,b+n+1,cmp);
		int flag=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]+b[i]>x)
			{
				flag=1;
				break;
			}
		}
		if(flag) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	 } 
	return 0;
}

在这里插入图片描述
在这里插入图片描述

题意

给 a (第一场比赛的 第100名 的得分), b(第一场的 前100名 在第二场的最少得分) , c (第二场比赛的 第100名 的得分), d (第二场的 前100名 在第一场的最少得分),让你求两场总得分的第100名最小可能是多少分

思路

50人第一场a+第二场c
50人第一场a+第二场b
50人第一场d+第二场c
第100名就是第二大的

代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e7+10;
const int mod=10007;
int p[5];
int main()
{
	ios::sync_with_stdio(false);
	int t,a,b,c,d;
	cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d;
		p[1]=a+c;
		p[2]=a+b;
		p[3]=c+d;
		sort(p+1,p+3+1);
		cout<<p[2]<<endl;
	 } 
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值