codeforce 610 div2 C. Petya and Exam

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

Petya and Exam


题意

Petya 要参加考试 Petya 写简单题用 a分钟 写难题用b分钟 一共有T分钟.
这场考试鼓励提前交卷
有以下规则

  1. Petya 可以 在任意 时刻交卷
  2. 每道题目有时限t,如果在t前未完成 则本场考试为0分
  3. 每道题目的固定得分为1分
    求Petya 能获得的最大分数

思路

感性 证明一波
先根据每个题目t的来排序
在每个题目截止前1s(完成此题前 其他题目的要求)
写最多的简单题
再写难题会取得最多的分数

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

AC代码

#include <bits/stdc++.h>
#define endl "\n" 
#define INF 0x3f3f3f3f3f3f3f3f
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
using namespace std;
typedef long long ll;
const  ll mod = 998244353;
const   double  PI = acos(-1.0);
const double EI = exp(1.0);
const int  N = 1e6+10;
const double  eps = 1e-8;
struct question{
	ll dege;
	ll t;
}qe[N];
bool cmp(question a, question b)
{
	if (a.t == b.t)
		return a.dege < b.dege;
	return a.t < b.t;
}
void solve()
{
	int n;
	ll T,a,b;
	ll num = 0;
	ll sa = 0,sb=0;
	cin >> n >> T >> a >> b;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		if (x == 0)
		{
			qe[i].dege = a;
			sa++;
		}
		else
		{
			qe[i].dege = b;
			sb++;
		}
	}
	for (int i = 1; i <= n; i++)
		cin >> qe[i].t;
	sort(qe + 1, qe + 1 + n, cmp);
	qe[n + 1].t = T + 1;
	ll ans = 0;
	ll ca = 0, cb = 0;
	for (int i = 1; i <= n+1; i++)
	{
		ll cur = ca * a + cb * b;
		ll time = qe[i].t - cur-1;
		if (time >= 0)
		{
			ll  ta = min(time / a, sa - ca);
			time -= ta * a;
			ll tb = min(time / b, sb - cb);
			ans = max(ans, ta + tb + ca + cb);
		}
		if (qe[i].dege == a)ca++;
		else
			cb++;
	}
	cout << ans << endl;
}
int main()
{
	 std::ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t; while (t--)
	solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值