补题报告 个人赛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 nnpackets with inflatable balloons, where ii-th of them has exactly aiai balloons 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
题解:就是把n个气球带分开保证每人起码都有气球,问是否能使他们两个的气球数量不同,如果不行输出1
排个序把最少气球的分给一个人其他的分给另外一个人就可以了。
注意输出的是序号
#include<iostream>
#include <algorithm>
using namespace std;
struct ballon{
    int x;
    int num;
};
bool cmp(ballon p,ballon q){
        return p.x<q.x;
}
int main(){
    int n,sum1,sum2;
    ballon a[1001];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].x;
        a[i].num=i+1;
    }
    if(n<2){
        cout<<-1<<endl;
    }
    else{
        sort(a,a+n,cmp);
        sum1=a[0].x;
        sum2=a[1].x;
        if(n==2&&sum1==sum2){
            cout<<-1<<endl;
            return 0;
        }
        for(int i=2;i<n;i++){
            sum2+=a[i].x;
        }
        cout<<1<<endl;
        cout<<a[0].num<<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 BBbitcoins.

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
题解:就是记录奇数的个数和偶数的个数如果相同就把他们和后面一个数分开记录分开用到的钱,然后排个序贪心,从最小钱的数开始计算,只
要小于等于b就接着算。(一开始以为只能从左到右进行计算)
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n,b,sum=0,ans=0,k=0;
    int flagj=0;
    int flago=0;
    int a[1001];
    int cost[1001];
    cin>>n>>b;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            flago++;
        }
        else{
            flagj++;
        }
        if(flagj==flago){
            if(i+1==n){
                break;
            }
            else{
                sum=abs(a[i+1]-a[i]);
                cost[k]=sum;
                k++;
            }
        }
    }
    sort(cost,cost+k);
    for(int i=0;i<k;i++){
        if(b>=cost[i]){
            ans++;
            b=b-cost[i];
        }
        else{
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
} 

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
题解:给定每个酒店的坐标再给每个酒店之间相隔的最小距离,问还可以再加入多少个酒店。如果前一个酒店+d坐标和后一个酒店-d坐标相等
那么他们之间只能有一个酒店sum++,如果后一个酒店-前一个酒店的距离大于2d表面他们之间有2个酒店sum+=2。最后的酒店和最前的酒店另外判断就好
#include<iostream>
using namespace std;
int main(){
    int n,d,sum=0;
    int a[1001];
    cin>>n>>d;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=2;i<=n;i++){
        if(a[i]-d==a[i-1]+d){
            sum++;
        }
        if(a[i]-d>a[i-1]+d){
            sum+=2;
        }
    }
    cout<<sum+2;
}

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 nn positions 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 lilito 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
题解:题目意思就是从i-j玫瑰花数量*百合花数量要最大,其实就一个规律只要交叉放就好了。
#include<iostream>
using namespace std;
int main(){
    int n,m;
    int a[1001],b[1001];
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=n;i++){
        if(i%2){
            cout<<1; 
        }
        else{
            cout<<0;
        }
    }
    cout<<endl;
    return 0;
} 

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
题解:给出 n 个数字,让从这个序列中选一对数 (a,b),使得从左边数第一个 a 出现的位置大于从右边数第一个 b 出现的位置,求符合要求的对数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 1000001
#define MOD 1e9+7
#define E 1e-6
#define LL long long
using namespace std;
int a[N],bucket[N],vis[N];
int main()
{
    int n;
    scanf("%d",&n);
 
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(bucket[a[i]]++==0)//这个数字有几个 
            cnt++;//几种数字 
    }
    LL ans=0;
    for(int i=0;i<n;i++)
    {
        if(--bucket[a[i]]==0)
            cnt--;//如果这个数字没有了种类-1 
        if(!vis[a[i]])
        {    
            ans+=cnt; 
            vis[a[i]]=1;
        }
    }
    printf("%lld
",ans);
    return 0;
}


 
 
原文地址:https://www.cnblogs.com/liyongqi/p/12694871.html