A. Group of Students
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.

Help the university pick the passing rate in a way that meets these requirements.

Input

The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.

Output

If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.

Examples
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
Note

In the first sample the beginner group has 7 students, the intermediate group has 6 of them.

In the second sample another correct answer is 3.

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int m;
int a[];
int main()
{
scanf("%d",&m);
int he=;
for(int i=;i<=m;i++)
{
scanf("%d",&a[i]);
he+=a[i];
}
int x,y;
int sum=;
int ans=;
scanf("%d %d",&x,&y);
for(int i=;i<=m;i++)
{
sum+=a[i];
if(sum>y)
{ printf("0\n");
return ;
}
if((sum>=x&&sum<=y)&&(he-sum>=x&&he-sum<=y))
{
printf("%d\n",i+);
return ;
}
}
printf("0\n");
return ;
}
B. Flag Day
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:

  • overall, there must be m dances;
  • exactly three people must take part in each dance;
  • each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).

The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.

You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 105) and m (1 ≤ m ≤ 105) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.

Output

Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.

Examples
Input
7 3
1 2 3
1 4 5
4 6 7
Output
1 2 3 3 2 2 1 
Input
9 3
3 6 9
2 5 8
1 4 7
Output
1 1 1 2 2 2 3 3 3 
Input
5 2
4 1 5
3 1 2
Output
2 3 1 1 3 

题意:n个舞者 m个舞 每个舞蹈由3个不同的舞者组成 并且每个舞者的衣着颜色不同 问你n个舞者的衣着分别为什么 (1,2,3代表三种颜色)
题解:具体看代码 大致思想就是 固定第i位置的舞者的衣着为i 通过交换位置 向上对齐
 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m;
int re[];
int a[][];
int mp[][];
int aa,bb,cc;
int main()
{
scanf("%d %d",&n,&m);
memset(mp,,sizeof(mp));
scanf("%d %d %d",&aa,&bb,&cc);
mp[aa][]=;
mp[bb][]=;
mp[cc][]=;
a[][]=aa;a[][]=bb;a[][]=cc;
for(int i=;i<=m;i++){
scanf("%d %d %d",&aa,&bb,&cc);
a[i][]=aa;a[i][]=bb;a[i][]=cc;
for(int j=;j<=;j++){
if(mp[aa][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
if(mp[bb][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
if(mp[cc][j]==){
if(j!=){
swap(a[i][],a[i][j]);
}
}
}
mp[a[i][]][]=;
mp[a[i][]][]=;
mp[a[i][]][]=;
}
for(int j=;j<=;j++)
{
for(int i=;i<=n;i++)
{
re[a[i][j]]=j;
}
}
for(int i=;i<=n;i++)
printf("%d ",re[i]);
printf("\n");
return ;
}
C. Knight Tournament
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.

As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:

  • There are n knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to n.
  • The tournament consisted of m fights, in the i-th fight the knights that were still in the game with numbers at least li and at most ri have fought for the right to continue taking part in the tournament.
  • After the i-th fight among all participants of the fight only one knight won — the knight number xi, he continued participating in the tournament. Other knights left the tournament.
  • The winner of the last (the m-th) fight (the knight number xm) became the winner of the tournament.

You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number b was conquered by the knight number a, if there was a fight with both of these knights present and the winner was the knight number a.

Write the code that calculates for each knight, the name of the knight that beat him.

Input

The first line contains two integers n, m (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ nli ≤ xi ≤ ri) — the description of the i-th fight.

It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.

Output

Print n integers. If the i-th knight lost, then the i-th number should equal the number of the knight that beat the knight number i. If the i-th knight is the winner, then the i-th number must equal 0.

Examples
Input
4 3
1 2 1
1 3 3
1 4 4
Output
3 1 4 0 
Input
8 4
3 5 4
3 7 6
2 8 8
1 8 1
Output
0 8 4 6 4 8 6 1 
Note

Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.

题意:n个人 m场比赛 x战胜了 [l,r]中除了已经被淘汰的和他本身的人 输出每个人是被谁战胜的

题解:set

 #include<bits/stdc++.h>
#define ll __int64
//code by drizzle
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
set<int> s;
set<int>::iterator it,itt;
int n,m;
int a[];
int l,r,x;
int main()
{
scanf("%d %d",&n,&m);
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
s.insert(i);
for(int i=;i<=m;i++)
{
scanf("%d %d %d",&l,&r,&x);
it=s.lower_bound(l);
for(;(*it)<=r&&it!=s.end();it=itt){
a[*it]=x;
itt=it;
itt++;
s.erase(*it);
}
s.insert(x);
a[x]=;
}
for(int i=;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return ;
}
/*
11 6
1 2 2
7 8 7
3 4 4
6 9 6
5 10 10
2 11 11
*/
E. Compartments
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.

The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.

However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.

After all the swaps each compartment should either have no student left, or have a company of three or four students.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.

Output

If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.

Examples
Input
5
1 2 2 4 3
Output
2
Input
3
4 1 1
Output
2
Input
4
0 3 0 4
Output
0

题意:给你n个数 数的范围为0~4  经过最少的操作(每次改变1) 使得n个数的目标状态为{0,3,4}

题解:恶心分类

 #include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
map<int,int>mp;
int exm;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&exm);
mp[exm]++;
}
if(mp[]>=mp[])
{
int len=mp[]-mp[];
int jishu=mp[]+(len/)*;
mp[]=mp[]+len/+mp[];
len=len%;
if(len==)
printf("%d\n",jishu);
if(len==)
{
if(mp[]>=)
printf("%d\n",jishu+);
else if(mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
if(len==)
{
if(mp[]>=||mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
}
else
{
int len=mp[]-mp[];
int jishu=mp[]+(len/)*;
mp[]=mp[]+(len/)*+mp[];
len=len%;
if(len==)
printf("%d\n",jishu);
if(len==)
{
if(mp[]>=)
printf("%d\n",jishu+);
else if(mp[]>=)
printf("%d\n",jishu+);
else
printf("-1\n");
}
if(len==)
{
printf("%d\n",jishu+);
}
}
return ;
}

Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

  4. Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)

    脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...

  5. Codeforces Round #207 (Div. 2) A. Group of Students

    #include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...

  6. Codeforces Round #207 (Div. 1)B(数学)

    数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...

  7. Codeforces Round #207 (Div. 2)C

    读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...

  8. Codeforces Round #207 (Div. 2)

    A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...

  9. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

随机推荐

  1. python怎么安装requests、beautifulsoup4等第三方库

    零基础学习python最大的难题之一就是安装所有需要的软件,下面来简单介绍一下如何安装用pip安装requests.beautifulsoup4等第三方库:   方法/步骤     点击开始,在运行里 ...

  2. java-HttpGetPost-图片字节流上传

    在java程序开发中经常用到与服务端的交互工作,主要的就是传递相应的参数请求从而获取到对应的结果加以处理 可以使用Get请求与Post请求,注意!这里的Get请求不是通过浏览器界面而是在程序代码中设置 ...

  3. 20181120-6 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 03

    此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制地址    [https://git.coding.n ...

  4. 20181023-10 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 07

    作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2290 Scrum master:范靖旋 一.小组介绍 组长:王一可 组员: ...

  5. 2018软工实践—Alpha冲刺(6)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 测试服务器并行能力 学习MSI.CUDA ...

  6. Task Class .net4.0异步编程类

    文章:Task Class 地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.tasks.task?view=netfra ...

  7. C++ Primer Plus学习:第五章

    C++入门第五章:循环和关系表达式 for循环 for循环的组成部分 设置初始值. 执行测试,看循环是否应该继续执行. 执行循环操作. 更新用于测试的值. 以上操作由括号括起,每个部分均是一个表达式, ...

  8. java 抽象类&接口

    1,抽象类中有构造函数吗? 有,用于给子类对象进行初始化.   2,抽象关键字不可以和那些关键字共存? private 不行 static 不行 final 不行   final关键字: 1,fina ...

  9. C++对象内存布局测试总结

    C++对象内存布局测试总结 http://hi.baidu.com/����/blog/item/826d38ff13c32e3a5d6008e8.html 上文是半年前对虚函数.虚拟继承的理解.可能 ...

  10. IT就业·软件工程之我见

    随着计算机技术的飞速发展,让人们深切感受到科技让生活更美好的真正含义. 现如今我们的正常生活,社交都越来越离不开网络和终端,因特网和各种终端设备的组合让我们即使相距千里,也能面对面对话交流:购物,我们 ...