2018国庆第三场个人赛

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/82936228

 CodeForces 1042A

 There are n benches in the Berland Central park. It is known that ai people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.

Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k.

Nobody leaves the taken seat during the whole process.

Input

The first line contains a single integer n(1≤n≤100)— the number of benches in the park.

The second line contains a single integer m(1≤m≤10000)— the number of people additionally coming to the park.

Each of the next n lines contains a single integer ai (1≤ai≤100) — the initial number of people on the i-th bench.

Output

Print the minimum possible k and the maximum possible k, where k is the maximum number of people sitting on one bench after additional m people came to the park.

Sample Input

扫描二维码关注公众号,回复: 3437167 查看本文章

Input

4
6
1
1
1
1

Output

3 7

Input

1
10
5

Output

15 15

Input

3
6
1
6
5

Output

6 12

Input

3
7
1
6
5

Output

7 13

Hint

In the first example, each of four benches is occupied by a single person. The minimum k

is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum k is 7

. That requires all six new people to occupy the same bench.

The second example has its minimum k

equal to 15 and maximum k equal to 15, as there is just a single bench in the park and all 10 people will occupy it.

题意:n个板凳  有m个人要来  现在第i个板凳上有ai个人   k是板凳上最多的人  k的范围是l<=k<=r 求l跟r

思路:l的情况是先填满在从头开始补  能填满一个情况 不能填满一个情况  r的情况是ai的最大值加m

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<char,ll> M;
int n,m;
int a[101010]={0};
bool cmp(int p,int q)
{
    return p>q;
}
int main()
{
    int i,p,c,maxx=0,ans2=0,ans1=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,cmp);
    maxx=a[0];
    ans2=a[0]+m;
    for(i=1;i<n;i++)
    {
        while(a[i]<a[0])
        {
            a[i]++;
            m--;
        }
    }
    if(m>0)
    {
        if(m%n==0)
            ans1=m/n+a[0];
        else
            ans1=m/n+a[0]+1;
    }
    else
        ans1=a[0];
    cout<<ans1<<" "<<ans2;
    return 0;
}

CodeForces 1051B

 You are given a set of all integers from l to r inclusive, l<r, (r−l+1)≤3⋅105 and (r−l) is always odd.

You want to split these numbers into exactly r−l+12 pairs in such a way that for each pair (i,j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

Input

The only line contains two integers l and r (1≤l<r≤1018, r−l+1≤3⋅105, (r−l) is odd).

Output

If any solution exists, print "YES" in the first line. Each of the next r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r−l+1) numbers should be pairwise distinct and should have values from l to r inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print "NO".

Sample Input

Input

1 8

Output

YES
2 7
4 1
3 8
6 5

这个题纯属是猜的  只有成对数时才YES  相邻两个GCD肯定为1

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<char,ll> M;
int n,m;
int a[101010]={0};
int main()
{
    ll l,r,i,j,p=0;
    cin>>l>>r;
    p=(r-l+1);
    if(p%2!=0)
        cout<<"NO"<<endl;
    else
    {
        p=p/2;
        cout<<"YES"<<endl;
        for(i=l;i<=r;i+=2)
        {
            cout<<i<<" "<<i+1<<endl;
        }
    }
    return 0;
}

CodeForces 1042B

Berland shop sells n kinds of juices. Each juice has its price ci. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.

Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.

Input

The first line contains a single integer n(1≤n≤1000)— the number of juices.

Each of the next n lines contains an integer ci (1≤ci≤100000) and a string si — the price of the i-th juice and the vitamins it contains. String si contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string si. The order of letters in strings si is arbitrary.

Output

Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.

Sample Input

Input

4
5 C
6 B
16 BAC
4 A

Output

15

Input

2
10 AB
15 BA

Output

-1

Input

5
10 A
9 BC
11 CA
4 A
5 B

Output

13

Input

6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA

Output

250

Input

2
5 BA
11 CB

Output

16

Hint

In the first example Petya buys the first, the second and the fourth juice. He spends 5+6+4=15

and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.

In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".

题意:补维生素ABC 求最小花费

暴力枚举

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
const int  MAX=1010010;
map<ll,ll> M;
int main()
{
    ll n,i,j,a=MAX,b=MAX,c=MAX,ab=MAX,ac=MAX,bc=MAX,abc=MAX,x,minn=MAX;
    char s[4];
    ll ans=0;
    cin>>n;
    while(n--)
    {
        cin>>x>>s;
        if(strcmp(s,"A")==0)
            a=min(a,x);
        if(strcmp(s,"B")==0)
            b=min(b,x);
        if(strcmp(s,"C")==0)
            c=min(c,x);
        if(strcmp(s,"AB")==0||strcmp(s,"BA")==0)
            ab=min(x,ab);
        if(strcmp(s,"AC")==0||strcmp(s,"CA")==0)
            ac=min(ac,x);
        if(strcmp(s,"BC")==0||strcmp(s,"CB")==0)
            bc=min(bc,x);
        if(strcmp(s,"ABC")==0||strcmp(s,"ACB")==0||strcmp(s,"BAC")==0||strcmp(s,"BCA")==0||strcmp(s,"CAB")==0||strcmp(s,"CBA")==0)
            abc=min(abc,x);
    }
    //cout<<a<<" "<<b<<" "<<c<<" "<<ab<<" "<<ac<<" "<<bc<<" "<<abc<<endl;
    if(a+b+c<=minn)
        minn=a+b+c;
    if(a+bc<=minn)
        minn=a+bc;
    if(ab+ac<=minn)
        minn=ab+ac;
    if(ab+bc<=minn)
        minn=ab+bc;
    if(ab+abc<=minn)
        minn=ab+abc;
    if(b+ac<=minn)
        minn=a+bc;
    if(c+ab<=minn)
        minn=c+ab;
    if(a+b+c<=minn)
        minn=a+b+c;
    if(minn==MAX)
        cout<<"-1"<<endl;
    else
        cout<<minn<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/82936228