Codeforces Round #429 (Div. 2)

A. Generous Kefa
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.

Next line contains string s — colors of baloons.

Output

Answer to the task — «YES» or «NO» in a single line.

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
4 2
aabb
output
YES
input
6 3
aacaab
output
NO
Note

In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.

In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».

思路:重复的气球的个数如果超过人数就NO。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 int flag[200];
 7 int main(){
 8     int n,k;
 9     cin>>n>>k;
10     char a[105];
11     memset(flag,0,sizeof(flag));
12     cin>>a;
13     int mx=0;
14     for(int i=0;i<strlen(a);i++){
15         flag[a[i]]++;
16         if(mx<flag[a[i]]){
17             mx=flag[a[i]];
18         }
19     }
20     if(mx>k) cout<<"NO"<<endl;
21     else cout<<"YES"<<endl;
22     return 0;
23 }

 

B. Godsend
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

Input

First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.

Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).

Examples
input
4
1 3 2 3
output
First
input
2
2 2
output
Second
Note

In first sample first player remove whole array in one move and win.

In second sample first player can't make a move and lose.

题目大意:两人玩游戏,第一个人取和为奇数的区间,第二个取和为偶数的区间。直到某人无法操作,某人输。

思路:只要判断整个数组是否有奇数,如果没有奇数,那么second赢,否则first赢。(ps:如果数组和为奇数,那么一次就赢了,如果是偶数,且存在奇数,那么往后必定first赢,因为操作最优,只有当不存在奇数,first无法操作就second 赢)

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 int main(){
 7     int n;
 8     cin>>n;
 9     int tmp;
10     int flag=0;
11     long long int sum=0;
12     for(int i=0;i<n;i++){
13         scanf("%d",&tmp);
14         sum+=tmp;
15         if(tmp%2==1) flag=1;
16     }
17     if(sum%2==1){
18         cout<<"First"<<endl;
19         return 0;
20     }
21     if(sum%2==0&&flag==0){
22         cout<<"Second"<<endl;
23         return 0;
24     }
25     cout<<"First"<<endl;
26     return 0;
27 }
C. Leha and Function
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.

But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists of mintegers. For all i, j such that 1 ≤ i, j ≤ m the condition Ai ≥ Bj holds. Help Leha rearrange the numbers in the array A so that the sum  is maximally possible, where A' is already rearranged array.

Input

First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B.

Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A.

Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.

Output

Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.

Examples
input
5
7 3 5 3 4
2 1 3 2 3
output
4 7 3 5 3
input
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2
output
2 6 4 5 8 8 6

题目大意:看的模模糊糊~晕

碎觉碎觉,明天看,玩了这么久,废了废了╮(╯_╰)╭

 

posted @ 2017-08-19 00:30  ISGuXing  阅读(275)  评论(0编辑  收藏  举报