提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
题意
Petya 要参加考试 Petya 写简单题用 a分钟 写难题用b分钟 一共有T分钟.
这场考试鼓励提前交卷
有以下规则
- Petya 可以 在任意 时刻交卷
- 每道题目有时限t,如果在t前未完成 则本场考试为0分
- 每道题目的固定得分为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;
}