2020.4.12--个人赛

A - Balloons

There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.

Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought nn packets with inflatable balloons, where ii-th of them has exactly aiaiballoons inside.

They want to divide the balloons among themselves. In addition, there are several conditions to hold:

  • Do not rip the packets (both Grigory and Andrew should get unbroken packets);
  • Distribute all packets (every packet should be given to someone);
  • Give both Grigory and Andrew at least one packet;
  • To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.

Help them to divide the balloons or determine that it's impossible under these conditions.

Input

The first line of input contains a single integer nn (1n101≤n≤10) — the number of packets with balloons.

The second line contains nn integers: a1a1, a2a2, …, anan (1ai10001≤ai≤1000) — the number of balloons inside the corresponding packet.

Output

If it's impossible to divide the balloons satisfying the conditions above, print 1−1.

Otherwise, print an integer kk — the number of packets to give to Grigory followed by kk distinct integers from 11 to nn — the indices of those. The order of packets doesn't matter.

If there are multiple ways to divide balloons, output any of them.

Examples

Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1

Note

In the first test Grigory gets 33 balloons in total while Andrey gets 11.

In the second test there's only one way to divide the packets which leads to equal numbers of balloons.

In the third test one of the boys won't get a packet at all.

题意:两个人买了n袋气球,每袋气球里面有ai个气球,现在要把这些气球分给两个人,满足下列要求:

不要撕毁包(格里戈里和安德鲁都应该得到完整的包);
分发所有的数据包(每个包都应该给某人);
给格里戈里和安德鲁至少一包;
为了提供更多的乐趣,Grigory包中的气球总数不应该等于Andrew包中的气球总数。
暴力  把总发气球数/2,注意精度,用浮点数,取整会错,如果有一袋气球不等于sum/2,就输出,否则就没有这样的结果

#include<bits/stdc++.h>
using namespace std;
map<int,int>m;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,a[100],sum=0,flag=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i],sum+=a[i],m[a[i]]=i+1;
    sort(a,a+n,cmp);
    if(n>1)
    {
        for(int i=0; i<n; i++)
            if (a[i]<sum*1.0/2)
            {
                cout<<1<<endl<<m[a[i]]<<endl;
                flag=1;
                break;
            }
    }
if(!flag)
    cout<<-1<<endl;
    return 0;

}

B - Cutting

There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.

There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.

Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, [4,1,2,3,4,5,4,4,5,5][4,1,2,3,4,5,4,4,5,5] → two cuts → [4,1|2,3,4,5|4,4,5,5][4,1|2,3,4,5|4,4,5,5]. On each segment the number of even elements should be equal to the number of odd elements.

The cost of the cut between xx and yy numbers is |xy||x−y|bitcoins. Find the maximum possible number of cuts that can be made while spending no more than BB bitcoins.

Input

First line of the input contains an integer nn (2n1002≤n≤100) and an integer BB (1B1001≤B≤100) — the number of elements in the sequence and the number of bitcoins you have.

Second line contains nn integers: a1a1, a2a2, ..., anan (1ai1001≤ai≤100) — elements of the sequence, which contains the equal number of even and odd numbers

Output

Print the maximum possible number of cuts which can be made while spending no more than BB bitcoins.

Examples

Input
6 4
1 2 5 10 15 20
Output
1
Input
4 10
1 3 2 4
Output
0
Input
6 100
1 2 3 4 5 6
Output
2

Note

In the first sample the optimal answer is to split sequence between 22 and 55. Price of this cut is equal to 33 bitcoins.

In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.

In the third sample the sequence should be cut between 22and 33, and between 44 and 55. The total price of the cuts is 1+1=21+1=2 bitcoins.

题意:给出一段数列,里面有N个数ai,奇数个数和偶数个数相同,然后你可以在奇数和偶数个数相等的时候,你就可以剪一个片段,需要花费|a[i]-a[i+1]|。现在总共预算是b,让你在b预算内,尽可能的多剪片段,输出最多的剪的次数。

题解:贪心  先把所有能减的片段,奇数和偶数个数相等的时候,把花费存起来,然后排个序,从前面累加,如果没有超出预算b剪的次数就++

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a[110],ans=0,cnt1=0,cnt2=0,b[110],c=0,sum=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
         cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if(a[i]%2) cnt1++;
         else cnt2++;
         if(cnt1==cnt2&&i+1<n)
           b[c++]=abs(a[i]-a[i+1]);
    }
    sort(b,b+c);
    for(int i=0;i<c;i++)
    {
        sum+=b[i];
        if(sum<=m)
            ans++;
        else break;
    }
    cout<<ans;
    return 0;
}

C - Convert to Ones

You've got a string a1,a2,,ana1,a2,…,an, consisting of zeros and ones.

Let's call a sequence of consecutive elements ai,ai+1,,ajai,ai + 1,…, aj (1ijn1≤ i≤ j≤ n) a substring of string aa.

You can apply the following operations any number of times:

  • Choose some substring of string aa (for example, you can choose entire string) and reverse it, paying xx coins for it (for example, «0101101» → «0111001»);
  • Choose some substring of string aa (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying yycoins for it (for example, «0101101» → «0110001»).

You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.

What is the minimum number of coins you need to spend to get a string consisting only of ones?

Input

The first line of input contains integers nn, xx and yy (1n300000,0x,y1091 ≤ n ≤ 300000,0≤x,y≤109) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).

The second line contains the string aa of length nn, consisting of zeros and ones.

Output

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 00, if you do not need to perform any operations.

Examples

Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0

Note

In the first sample, at first you need to reverse substring [12][1…2], and then you need to invert substring [25][2…5].

Then the string was changed as follows:

«01000» → «10000» → «11111».

The total cost of operations is 1+10=111+10=11.

In the second sample, at first you need to invert substring [11][1…1], and then you need to invert substring [35][3…5].

Then the string was changed as follows:

«01000» → «11000» → «11111».

The overall cost is 1+1=21+1=2.

In the third example, string already consists only of ones, so the answer is 00.

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 300005;
char s[MAXN];
int main() {
    int n, a, b;
    while(scanf("%d %d %d", &n, &a, &b) != EOF) {
        scanf("%s", s);
        long long temp = 0;
        int len = strlen(s);
        for(int i = 0; i < len; i++) {
            int flag = i;
            if(s[flag] == '0') {
                temp++;
                while(s[flag] == '0' && flag < len)
                    flag++;
                i = flag;
            }
        }
        if(temp == 0) {
            printf("0\n");
        } else {
            temp--;
            printf("%lld\n", 1ll*min(temp*a + b, b*(temp + 1)));
        }
    }
    
}
 

D - Sonya and Hotels

Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has nn hotels, where the ii-th hotel is located in the city with coordinate xixi. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to dd. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original nn hotels to the new one is equal to dd.

Input

The first line contains two integers nn and dd (1n1001≤n≤100, 1d1091≤d≤109) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains nn different integers in strictly increasing order x1,x2,,xnx1,x2,…,xn (109xi109−109≤xi≤109) — coordinates of Sonya's hotels.

Output

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to dd.

Examples

Input
4 3
-3 2 9 16
Output
6
Input
5 2
4 8 11 18 19
Output
5

Note

In the first example, there are 66 possible cities where Sonya can build a hotel. These cities have coordinates 6−6, 55, 66, 1212, 1313, and 1919.

In the second example, there are 55 possible cities where Sonya can build a hotel. These cities have coordinates 22, 66, 1313, 1616, and 2121.

题意:

在一条直线上有n家宾馆,现在要新建一家宾馆,要求新建的宾馆与原来的n家宾馆的最小距离是d,且每个位置只能建一家宾馆

求满足要求要求的位置的个数

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const int N = 105;
map<int,int>mp;
int arr[N];
int check(int n,int x,int d){
    for(int i=0;i<n;i++){
        if(fabs(arr[i]-x)<d) return 0;
    }
    return 1;
}
int main(){
    int n,d;
    scanf("%d%d",&n,&d);
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        mp[arr[i]]=1;
    }  
    int ans=0;
    for(int i=0;i<n;i++){
        int x=arr[i]-d;
        int y=arr[i]+d;
        if(check(n,x,d)&&!mp[x]){
          ans++;
          mp[x]=1;    
        }
        if(check(n,y,d)&&!mp[y]){
          ans++; 
          mp[y]=1;
        }
    }
    printf("%d\n",ans);
    }

E - Sonya and Exhibition

Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.

There are nn flowers in a row in the exhibition. Sonya can put either a rose or a lily in the ii-th position. Thus each of nnpositions should contain exactly one flower: a rose or a lily.

She knows that exactly mm people will visit this exhibition. The ii-th visitor will visit all flowers from lili to riri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.

Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

Input

The first line contains two integers nn and mm (1n,m1031≤n,m≤103) — the number of flowers and visitors respectively.

Each of the next mm lines contains two integers lili and riri (1lirin1≤li≤ri≤n), meaning that ii-th visitor will visit all flowers from lili to riri inclusive.

Output

Print the string of nn characters. The ii-th symbol should be «0» if you want to put a rose in the ii-th position, otherwise «1» if you want to put a lily.

If there are multiple answers, print any.

Examples

Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010

Note

In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;

  • in the segment [13][1…3], there are one rose and two lilies, so the beauty is equal to 12=21⋅2=2;
  • in the segment [24][2…4], there are one rose and two lilies, so the beauty is equal to 12=21⋅2=2;
  • in the segment [25][2…5], there are two roses and two lilies, so the beauty is equal to 22=42⋅2=4.

The total beauty is equal to 2+2+4=82+2+4=8.

In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;

  • in the segment [56][5…6], there are one rose and one lily, so the beauty is equal to 11=11⋅1=1;
  • in the segment [14][1…4], there are two roses and two lilies, so the beauty is equal to 22=42⋅2=4;
  • in the segment [46][4…6], there are two roses and one lily, so the beauty is equal to 21=22⋅1=2.

The total beauty is equal to 1+4+2=71+4+2=7.

题意:小明家有一个长为n的花园(只有玫瑰花和百合花,且花只能放在整数位置,每个位置放一朵),有m个小朋友来他家参观,每个小朋友将会以li为起点,参观到ri。小朋友获得的愉悦感等同与从l到r的距离里,玫瑰花与百合花数量的乘积。问小明怎样摆放花才能使所以的小朋友获得的愉悦感最大,分别用01表示玫瑰花和百合花。

思路:高中学过,a+b=t,要使a×b最大,那么,a和b应该尽量接近。也就是说,如果a+b=3,那么a=1,b=2,或者b=1,a=2。如果a+b=4,那么a=2,b=2。这样的话,不管小朋友怎么参观,我们只要将玫瑰和百合间隔种植就可以了

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cout<<(i&1);
    cout<<endl;
   }

F - Sonya and Robots

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.

Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.

For example, if the numbers [1,5,4,1,3][1,5,4,1,3] are written, and Sonya gives the number 11 to the first robot and the number 44 to the second one, the first robot will stop in the 11-st position while the second one in the 33-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 44 to the first robot and the number 55 to the second one, they will meet since the first robot will stop in the 33-rd position while the second one is in the 22-nd position.

Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.

Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (pp, qq), where she will give pp to the first robot and qq to the second one. Pairs (pipi, qiqi) and (pjpj, qjqj) are different if pipjpi≠pj or qiqjqi≠qj.

Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.

Input

The first line contains a single integer nn (1n1051≤n≤105) — the number of numbers in a row.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1051≤ai≤105) — the numbers in a row.

Output

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.

Examples

Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7

Note

In the first example, Sonya can give pairs (11, 11), (11, 33), (11, 44), (11, 55), (44, 11), (44, 33), (55, 11), (55, 33), and (55, 44).

In the second example, Sonya can give pairs (11, 11), (11, 22), (11, 33), (22, 11), (22, 22), (22, 33), and (33, 22).

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
deque <char> q;
map<ll,ll> m;
set<ll> s;
int main()
{
    ll n,i,a[101001],b[100101];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=n-1;i>=0;i--)
    {
        b[i]=s.size();
        s.insert(a[i]);
    }
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(m[a[i]]==0)
            ans+=b[i];
        m[a[i]]++;
    }
    cout<<ans<<endl;
  }

猜你喜欢

转载自www.cnblogs.com/mxw000120/p/12726887.html