CF educational Codeforces Round C. Multi-judge solving

Source: Internet
Author: User
Tags integer numbers time limit

Original question:
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 the other different online judges. Each problem are denoted by its difficulty-a positive integer number. Difficulties was measured the same across all the judges (the problem with difficulty D on Decoforces was as hard as the PR Oblem with difficulty D on any other judge).

Makes have 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 with problem difficulty (d>=)
(no matter on why online judge was it).

Before starting this chosen list of problems, makes have already solved problems with maximum difficulty K.

With given conditions it's easy-to-see-makes sometimes can ' t solve all the chosen problems, no matter what order he C Hooses. So he wants the solve some problems on the other judges to finish solving problems from the 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 is ' t necessary to does problems from the chosen list one right after another.

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

Input
The first line contains the 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
The first example makes at first solves problems 1 and 2. Then on order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available is difficulties 5 and 6 on some other judge. Solving any of these would give makes opportunity to solve problem 3.

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

English:
Give you two numbers, N and K. This indicates that there is a problem with N, and K indicates the difficulty value that is currently obtained.
Next give you n number, to indicate the difficulty of n topic.
Users want to complete the n in the Codeforce, complete a problem, the user can get the difficulty value of the corresponding topic. But the user wants to complete a difficulty for the AI problem, then he must have completed a difficulty greater than or equal to 2xk of the topic. If the AI problem is more difficult than the current 2XK value, the user can go to other OJ brush problems, other OJ the problem of countless kinds of difficulty, save enough difficulty value can come back to continue to do AI.
Now ask the user how many questions you have at least other 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;
}

Ideas:

The topic is not very well understood.
First from small to large sort, with the initial given user's difficulty value K to do the problem, each do a question to see if you can update the K value, if you do the first problem, found that the difficulty value is not enough. Then go to other OJ do their current difficulty the highest can withstand the problem brush difficulty value, brush enough to come back to continue.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.