Codeforces Round #603 (Div. 2)

A. Sweet Problem

 

You have three piles of candies: red, green and blue candies:

  • the first pile contains only red candies and there are rr candies in it,
  • the second pile contains only green candies and there are gg candies in it,
  • the third pile contains only blue candies and there are bb candies in it.

Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.

Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

Input

The first line contains integer tt (1t10001≤t≤1000) — the number of test cases in the input. Then tt test cases follow.

Each test case is given as a separate line of the input. It contains three integers rr, gg and bb (1r,g,b1081≤r,g,b≤108) — the number of red, green and blue candies, respectively.

Output

Print tt integers: the ii-th printed integer is the answer on the ii-th test case in the input.

Example
input
Copy
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
output
Copy
1
2
2
10
5
9
Note

In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.

In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.

In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

#include <bits/stdc++.h>
#include <vector>
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
using namespace std;
#define ll long long
const int mxn = 1e3+10;
int n,m,k,a[mxn],t;
const int inf = 0x3f3f3f;
ll read()
{
    char ch ; int flag = 1; ll col = 0;
    ch=getchar();
    while(ch>'9' || ch<'0') {if(ch=='-') flag = -1 , ch = getchar();}
    while(ch<='9' && ch>='0') {col = col*10+ch-'0' , ch=getchar();}
    return flag*col;
}
int main()
{TLE;
    cin>>t;
    while(t--)
    {
        cin>>a[1]>>a[2]>>a[3];
        if(*max_element(a+1,a+4)==a[1]+a[2]+a[3]-*max_element(a+1,a+4) )
            cout<<*max_element(a+1,a+4)<<endl;
        else if( *max_element(a+1,a+4)>a[1]+a[2]+a[3]-*max_element(a+1,a+4)  )
            cout<<a[1]+a[2]+a[3]-*max_element(a+1,a+4)<<endl;
        else
            cout<<(a[1]+a[2]+a[3])/2<<endl;
    }
    return 0;
}

 

B. PIN Codes

A PIN code is a string that consists of exactly 44 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.

Polycarp has nn (2n102≤n≤10) bank cards, the PIN code of the ii-th card is pipi.

Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all nn codes would become different.

Formally, in one step, Polycarp picks ii-th card (1in1≤i≤n), then in its PIN code pipi selects one position (from 11 to 44), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.

Polycarp quickly solved this problem. Can you solve it?

Input

The first line contains integer tt (1t1001≤t≤100) — the number of test cases in the input. Then test cases follow.

The first line of each of tt test sets contains a single integer nn (2n102≤n≤10) — the number of Polycarp's bank cards. The next nn lines contain the PIN codes p1,p2,,pnp1,p2,…,pn — one per line. The length of each of them is 44. All PIN codes consist of digits only.

Output

Print the answers to tt test sets. The answer to each set should consist of a n+1n+1 lines

In the first line print kk — the least number of changes to make all PIN codes different. In the next nn lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.

Example
input
Copy
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139
output
Copy
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139

 

#include <bits/stdc++.h>
#include <vector>
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
using namespace std;
#define ll long long
#define pb push_back
set<int>st;
vector<int>v;
vector<string>vs;
map<string , int> mp;
const int inf = 0x3f3f3f;
const int mxn = 1e8+10;
int n,m,k,t,ans;
string str , sub ;
int main()
{TLE;
    cin>>t;
    while(t--)
    {
        mp.clear();vs.clear();
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>str;
            mp[str]++;
        }
        cout<<n-mp.size()<<endl;
        if(n==mp.size())
        {
            for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
                cout<<it->first<<endl;
        }
        else
        {
            for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
            {
                if(it->second>1)
                {
                    for(int k=1;k<it->second;k++)
                    {
                        str = it->first;
                        for(int i=0;i<4;i++)
                        {
                            int flag=0;
                            for(int j='0';j<='9';j++)
                            {
                                str[i] = j;
                                if(!mp.count(str))
                                {
                                    mp[str]++;
                                    flag = 1;
                                    break;
                                }
                            }
                            if(flag) break;
                        }
                    }
                    mp[it->first]=1;
                }
            }
            for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
                cout<<it->first<<endl;
        }
    }
    return 0;
}

 

 

 

 C. Everyone is a Winner!

On the well-known testing system MathForces, a draw of nn rating units is arranged. The rating will be distributed according to the following algorithm: if kk participants take part in this event, then the nn rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.

For example, if n=5n=5 and k=3k=3, then each participant will recieve an 11 rating unit, and also 22 rating units will remain unused. If n=5n=5, and k=6k=6, then none of the participants will increase their rating.

Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.

For example, if n=5n=5, then the answer is equal to the sequence 0,1,2,50,1,2,5. Each of the sequence values (and only them) can be obtained as n/k⌊n/k⌋ for some positive integer kk (where x⌊x⌋ is the value of xx rounded down): 0=5/70=⌊5/7⌋, 1=5/51=⌊5/5⌋, 2=5/22=⌊5/2⌋, 5=5/15=⌊5/1⌋.

Write a program that, for a given nn, finds a sequence of all possible rating increments.

Input

The first line contains integer number tt (1t101≤t≤10) — the number of test cases in the input. Then tt test cases follow.

Each line contains an integer nn (1n1091≤n≤109) — the total number of the rating units being drawn.

Output

Output the answers for each of tt test cases. Each answer should be contained in two lines.

In the first line print a single integer mm — the number of different rating increment values that Vasya can get.

In the following line print mm integers in ascending order — the values of possible rating increments.

Example
input
Copy
4
5
11
1
3
output
Copy
4
0 1 2 5 
6
0 1 2 3 5 11 
2
0 1 
3
0 1 3 

 

#include <bits/stdc++.h>
#include <vector>
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
using namespace std;
#define ll long long
#define pb push_back
set<int>st;
vector<int>v;
const int mxn = 1e8+10;
int n,m,k,t;
const int inf = 0x3f3f3f;
ll read()
{
    char ch ; int flag = 1; ll col = 0;
    ch=getchar();
    while(ch>'9' || ch<'0') {if(ch=='-') flag = -1 , ch = getchar();}
    while(ch<='9' && ch>='0') {col = col*10+ch-'0' , ch=getchar();}
    return flag*col;
}
int main()
{TLE;
    cin>>t;
    while(t--)
    {
        v.clear();
        cin>>n;
        v.push_back(0);
        for(int i=1;i<=n;i=n/(n/i)+1)
            v.pb(n/i);
        cout<<v.size()<<endl;
        sort(v.begin(),v.end());
        for(vector<int>::iterator it=v.begin();it!=v.end();it++)
            cout<<*it<<" ";
        cout<<endl;
    }
    return 0;
}

 

 

 

posted @ 2019-11-30 09:33  __MEET  阅读(443)  评论(0编辑  收藏  举报