codeforces 1530C Pursuit

链接:

https://codeforces.com/problemset/problem/1530/C

题意:

总共n长比赛,取n−n/4场最高分之和,求最少还要几场比赛自己的分数才能高于Ilya。

本题可以先将二者的分数都排序,自己的正序,llya的逆序。之后while循环,直到自己的分数大于llya退出循环,每次都让自己接下来的比赛得100分,llya的比赛得0分。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
int a[1000003];
int b[1000003];
bool cmp(int a, int b) {
	return a > b;
}
int main() {
	int T;
	cin >> T;
	while (T--) {
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		int n;
		cin >> n;
		int cntm = n - n / 4;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n; i++) {
			cin >> b[i];
		}
		sort(a, a + n);
		sort(b, b + n, cmp);
		int suma = 0, sumb = 0;
		for (int i = n / 4; i < n; i++) {
			suma += a[i];
		}
		for (int i = 0; i < cntm; i++) {
			sumb += b[i];
		}
		int ans = 0;
		int position = n / 4;
		while (suma < sumb)
		{
			ans++;
			n++;
			a[n - 1] = 100;
			b[n - 1] = 0;
			suma += 100;
			int temp = cntm;
			cntm = n - n / 4;
			if (temp == cntm) {
				suma -= a[position++];
			}
			else {
				sumb += b[temp];
			}
		}
		cout << ans;
		cout << endl;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值