Doors Breaking and Repairing(贪心)

You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.

There are n doors, the i-th door initially has durability equal to ai.

During your move you can try to break one of the doors. If you choose door i and its current durability is bi then you reduce its durability to max(0,bi−x) (the value x is given).

During Slavik’s move he tries to repair one of the doors. If he chooses door i and its current durability is bi then he increases its durability to bi+y (the value y is given). Slavik cannot repair doors with current durability equal to 0.

The game lasts 10100 turns. If some player cannot make his move then he has to skip it.

Your goal is to maximize the number of doors with durability equal to 0 at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally?

Input
The first line of the input contains three integers n, x and y (1≤n≤100, 1≤x,y≤105) — the number of doors, value x and value y, respectively.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤105), where ai is the initial durability of the i-th door.
Output
Print one integer — the number of doors with durability equal to 0 at the end of the game, if you and Slavik both play optimally.

Examples

Input
6 3 2
2 3 1 3 4 2
Output
6
Input
5 3 3
1 2 4 2 3
Output
2
Input
5 5 6
1 2 6 10 3
Output
2

思路:
就直接一直贪心就完了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <map>
#define INF 0x3f3f3f3f

using namespace std;
typedef long long ll;
const int maxn=100005;

int n,x,y;
int a[maxn];

int judge()
{
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)
        {
            a[i]=0;
            sum++;
            a[i+1]+=y;
            sort(a+i+1,a+n+1);
        }
        else
        {
            a[i]-=x;
            a[i]+=y;
            sort(a+i,a+n+1);
            if(a[i]>x&&x<=y)
                return sum;
        }
    }
    return sum;
}

int main()
{
    while(~scanf("%d%d%d",&n,&x,&y))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(x>y)
        {
            printf("%d\n",n);
            continue;
        }
        sort(a+1,a+n+1);
        int ans=judge();
        printf("%d\n",ans);
    }

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值