Petya and Exam【Codeforces 1282 C】【贪心】

Codeforces Round #610 (Div. 2) C


  有N道题目,题目有简单与困难之分,简单的题目花费A分钟,困难的题目花费B分钟,那么考试时间一共有T的情况下,我们是可以提前交卷的,但是有些时间限制,就是譬如说你现在第x分钟交卷,但是你这时候就是必须要完成所有的t[i]≤x的题目才行,不然就使算作0分。

  所以,这里直接按照限制时间t[i]升序排列来进行贪心即可。每次看看能不能补充额外的,譬如说现在的时间还能多出来做几道简单题之类的。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#define _ABS(x, y) ( x > y ? (x - y) : (y - x) )
#define lowbit(x) ( x&( -x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 2e5 + 7;
int N, T, A, B, easy, diff, op[maxN];
struct node
{
    int t, r, id;
    friend bool operator < (node e1, node e2) { return e1.r == e2.r ? e1.t < e2.t : e1.r < e2.r; }
}a[maxN];
int main()
{
    int Cas; scanf("%d", &Cas);
    while(Cas--)
    {
        scanf("%d%d%d%d", &N, &T, &A, &B);
        easy = diff = 0;
        for(int i=1; i<=N; i++)
        {
            a[i].id = i;
            scanf("%d", &a[i].t);
            op[i] = a[i].t;
            if(a[i].t) { a[i].t = B; diff++; }
            else { a[i].t = A; easy++; }
        }
        for(int i=1; i<=N; i++) scanf("%d", &a[i].r);
        int ans = 0, tmp;
        ll det;
        ll tim = 0, res;
        sort(a + 1, a + N + 1);
        a[N + 1].r = T + 1;
        for(int i=1; i<=N + 1 && tim <= T; i++)
        {
            if(tim < a[i].r)
            {
                res = a[i].r - tim - 1;
                tmp = i - 1;
                det = min(1LL * easy, res / A);
                res -= det * A;
                tmp += det;
                det = min(1LL * diff, res / B);
                tmp += det;
                ans = max(ans, tmp);
            }
            tim += a[i].t;
            if(op[a[i].id]) diff--;
            else easy--;
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wuliwuliii

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值