第一次个人排位赛(大二)

A - Bear and Five Cards

CodeForces - 680A

A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.

Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.

He is allowed to at most once discard two or three cards with the same number. Of course, he won’t discard cards if it’s impossible to choose two or three cards with the same number.

Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

Input

The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

Output

Print the minimum possible sum of numbers written on remaining cards.

Examples

Input

7 3 7 3 20

Output

26

Input

7 9 3 1 8

Output

28

Input

10 10 10 10 10

Output

20

Note

In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.

In the second sample, it’s impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.

In the third sample, all cards have the same number. It’s optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

AC代码:

#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;

int main()
{
    int a[5],f[1000]={0},i,s=0,ans,k=1000;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
        f[a[i]]++;
        s=s+a[i];
    }
    ans=s;
    for(i=0;i<5;i++)
    {
        if(f[a[i]]==2)
        {
            k=s-a[i]*2;
        }
        else if(f[a[i]]>2)
        {
            k=s-a[i]*3;
        }
        if(k<ans)
        {
            ans=k;
        }
    }
    printf("%d\n",ans);
    return 0;
}

B - Bear and Finding Criminals

CodeForces - 680B
There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|.

Limak is a police officer. He lives in a city a. His job is to catch criminals. It’s hard because he doesn’t know in which cities criminals are. Though, he knows that there is at most one criminal in each city.

Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.

You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

Input

The first line of the input contains two integers n and a (1 ≤ a ≤ n ≤ 100) — the number of cities and the index of city where Limak lives.

The second line contains n integers t1, t2, …, tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Output

Print the number of criminals Limak will catch.

Examples

Input

6 3
1 1 1 0 1 0

Output

3

Input

5 2
0 0 0 1 0

Output

1

Note

In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
这里写图片描述

Using the BCD gives Limak the following information:

There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.
There is one criminal at distance 1 from the third city — Limak doesn’t know if a criminal is in the second or fourth city.
There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city.
There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.

In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak’s city. There is only one city at distance 2 so Limak is sure where a criminal is.
这里写图片描述

AC代码:

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
    int n,a,c[110]={0},sum=0;
    scanf("%d%d",&n,&a);
    for(int i=1;i<=n;i++){
        scanf("%d",&c[i]);
    }
    int p1=a,p2=a;
    while(p1>=1&&p2<=n){
        if(c[p1]>0&&c[p2]>0){
            if(p1==p2){
                sum+=c[p1];
            }
            else{
                sum+=(c[p1]+c[p2]);
            }
        }
        p1--;p2++;
    }
    while(p1>=1){
        if(c[p1]>0){
            sum+=c[p1];
        }
        p1--;
    }
    while(p2<=n){
        if(c[p2]>0){
            sum+=c[p2];
        }
        p2++;
    }
    printf("%d\n",sum);

    return 0;
}

这是补上前一次个人排位赛的题解报告

猜你喜欢

转载自blog.csdn.net/wuyileiju__/article/details/81481246