cf Educational Codeforces Round 25 C. Multi-judge Solving

原题:
C. Multi-judge Solving
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).

Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, …, an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty d>=(ai/2)
(no matter on what online judge was it).

Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.

With given conditions it’s easy to see that Makes sometimes can’t solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.

For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.

Makes can solve problems on any judge at any time, it isn’t necessary to do problems from the chosen list one right after another.

Makes doesn’t have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

Input
The first line contains two integer numbers n, k (1 ≤ n ≤ 10^3, 1 ≤ k ≤ 10^9).

The second line contains n space-separated integer numbers a1, a2, …, an (1 ≤ ai ≤ 10^9).

Output
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

Examples
input
3 3
2 1 9
output
1
input
4 20
10 3 6 3
output
0
Note
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.

In the second example he can solve every problem right from the start.

中文:
给你两个数,n和k。其中表示有n道题目,k表示当前已经获得的难度值。
接下来给你n个数,表示n个题目的难度。
用户想在codeforce里面完成这n个题,完成一道题,用户就可以获得对应题目的难度值。但是用户想要完成一道难度为ai的题目,那么他之前必须完成过一道难度大于等于2×k的题目。如果ai题目的难度超过当前的2×k值,用户可以去别的oj刷题,别的oj的题目难度有无数种类,攒够难度值以后可以回来继续做ai。
现在问你用户最少在别的oj做多少题?

#include<bits/stdc++.h>
using namespace std;
int n,k;

int num[1001];



int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n>>k)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>num[i];
        }
        sort(num+1,num+1+n);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(num[i]<=k*2)
                k=max(k,num[i]);
            else
            {
                int m=1;
                int j;
                for(j=k*2;j*2<num[i];j=j*2)
                    m++;
                ans+=m;
            //    cout<<j<<endl;
                k=max(num[i],j);
            }
            //cout<<k<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}

思路:

题目不太好理解。
首先从小到大排序,用初始化给定用户的难度值k去做题,每做一道题就看看能不能更新k值,如果做到第i个题,发现难度值不够。那么就去别的oj做自己当前难度最高可以承受的题目刷难度值,刷够了回来继续即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值