A - Turn the Rectangles

CodeForces - 1008B

There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of rectangles.

Each of the next nn lines contains two integers wiwi and hihi (1≤wi,hi≤1091≤wi,hi≤109) — the width and the height of the ii-th rectangle.

Output

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input
3
3 4
4 6
3 5
Output
YES
Input
2
3 4
5 5
Output
NO

Note

In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

In the second test, there is no way the second rectangle will be not higher than the first one.

这题是之前写过的一道原题,博客里也有

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char s[];
while(~scanf("%s",s))
{
int k,ans=,t,ans2=,ans1=;
k=strlen(s);
for(int i=; i<k; i++)
{
if(s[i]=='')
ans++;
if(s[i]=='')
ans2++;
if(s[i]=='')
ans1++;
}
for(int i=; i<k; i++)
{
if(s[i]=='')
{
t=i;
break;
}
}
if(ans1>)
{
for(int i=; i<k; i++)
{
if(i==t)
{
for(int j=; j<=ans; j++)
{
printf("");
}
}
if(s[i]=='')
continue;
else
printf("%c",s[i]);
}
}
else
{
for(int i=; i<ans2; i++)
printf("");
for(int i=; i<ans; i++)
printf("");
}
printf("\n");
}
return ;
}

B - Reorder the Array

CodeForces - 1008C

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10,20,30,40][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input
7
10 1 1 1 5 5 3
Output
4
Input
5
1 1 1 1 1
Output
0

Note

In the first sample, one of the best permutations is [1,5,5,3,10,1,1][1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

题意:给你一个数组,让你重新排列,使得当前位置的数字比原来的数字大,求这样的位置最多有多少个

分析:

比如数组 10 1 1 1 5 5 3

从小到大排序  1 1 1 3 5 5 10

用两个指针来遍历,指针i与指针j,一开始指针i指在第1个数,指针j指在第2个数,如果a[j]>a[i],i指针向后移一位,ans++;否则,i指针还是指在原来的位置;j指针向后移,直到j>n。

思路:其实就是想让第一小的位置 放第二小的数字,第二小的位置放第三小的数字,以此类推

比如数组1 2 3 4 5 6  当排列为 2 3 4 5 6 1 时这样的位置有5个 最大

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,a[];
while(~scanf("%d",&n))
{
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
sort(a+,a++n);
int ans=,j=;
for(int i=; j<=n; j++)
{
if(a[j]>a[i])
{
i++;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

C - Romaji

CodeForces - 1008A

Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.

In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.

Help Vitya find out if a word ss is Berlanese.

Input

The first line of the input contains the string ss consisting of |s||s| (1≤|s|≤1001≤|s|≤100) lowercase Latin letters.

Output

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input
sumimasen
Output
YES
Input
ninja
Output
YES
Input
codeforces
Output
NO

Note

In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.

In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.

分析题意:元音字符有a e i o u,辅音字符是除了元音字符以外的字母,辅音字母后面只能跟元音字母,除了辅音字母n,它后面可以跟任意字符或者不跟字符;元音字符后面可以跟任意字符。给你一个字符串,如果满足以上条件,则输出yes,否则输出no

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char s[];
while(~scanf("%s",s))
{
int k,i;
k=strlen(s);
for(i=;i<k;i++)
{
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
{
continue;
}
else
{
if(s[i]!='n')
{
if(s[i+]=='a'||s[i+]=='e'||s[i+]=='i'||s[i+]=='o'||s[i+]=='u')
continue;
else if(i==k-)
break;
else
{
break;
}
}
}
}
if(i==k)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

D - Game Shopping

CodeForces - 1009A

Maxim wants to buy some games at the local game shop. There are nn games in the shop, the ii-th game costs cici.

Maxim has a wallet which can be represented as an array of integers. His wallet contains mm bills, the jj-th bill has value ajaj.

Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.

When Maxim stands at the position ii in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the ii-th game using this bill. After Maxim tried to buy the nn-th game, he leaves the shop.

Maxim buys the ii-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the ii-th game. If he successfully buys the ii-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.

For example, for array c=[2,4,5,2,4]c=[2,4,5,2,4] and array a=[5,3,4,6]a=[5,3,4,6] the following process takes place: Maxim buys the first game using the first bill (its value is 55), the bill disappears, after that the second bill (with value 33) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because c2>a2c2>a2, the same with the third game, then he buys the fourth game using the bill of value a2a2 (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value a3a3.

Your task is to get the number of games Maxim will buy.

Input

The first line of the input contains two integers nn and mm (1≤n,m≤10001≤n,m≤1000) — the number of games and the number of bills in Maxim's wallet.

The second line of the input contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤10001≤ci≤1000), where cici is the cost of the ii-th game.

The third line of the input contains mm integers a1,a2,…,ama1,a2,…,am (1≤aj≤10001≤aj≤1000), where ajaj is the value of the jj-th bill from the Maxim's wallet.

Output

Print a single integer — the number of games Maxim will buy.

Examples

Input
5 4
2 4 5 2 4
5 3 4 6
Output
3
Input
5 2
20 40 50 20 40
19 20
Output
0
Input
6 4
4 8 15 16 23 42
1000 1000 1000 1000
Output
4

Note

The first example is described in the problem statement.

In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.

In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.

题意:商店里有n个玩具,你的钱包里有m张票子,下面一行n个数分别代表第i个玩具的价格,再下面一行有m个数分别代表第j张票子的价值。如果你的第一张钞票的价值大于等于第i个玩具的价格,ans++,第一张钞票失效,现在的第一张变成了后面的那张钞票。求你能买到的玩具的数量

分析:其实这道题也用了双指针,唔,代码很容易看懂,题目说了,这个人是按照输入的顺序来买玩具的

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,m,c[],a[];//c数组代表玩具的价格,a数组代表票子的价值
while(~scanf("%d %d",&n,&m))
{
for(int i=;i<=n;i++)
scanf("%d",&c[i]);
for(int i=;i<=m;i++)
scanf("%d",&a[i]);
int j=,ans=;//ans表示买到的玩具的数量
for(int i=;i<=n;i++)
{
if(a[j]>=c[i])
{
ans++;
j++;
}//如果买到了,就用下一张票子来买,所以j++
if(j==m+)//当票子花光了就跳出
break;
}
printf("%d\n",ans);
}
return ;
}

E - Minimum Ternary String

CodeForces - 1009B

You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').

You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).

For example, for string "010210" we can perform the following moves:

  • "010210" →→ "100210";
  • "010210" →→ "001210";
  • "010210" →→ "010120";
  • "010210" →→ "010201".

Note than you cannot swap "02" →→ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.

You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).

String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1≤i≤|a|1≤i≤|a|, where |s||s| is the length of the string ss) such that for every j<ij<i holds aj=bjaj=bj, and ai<biai<bi.

Input

The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).

Output

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

Examples

Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
这题没读懂题,蛮心痛的,不过也没什么好心痛的,读懂了想了半个小时也没想出来
看了题解啧啧
题意:要你求最小字典序,前提是,0和1能互相交换,1和2能互相交换,但是0,2不能互相交换
分析:你会发现,1是可以分布在任意位置的,而2,0的位置相对是不变的,只要把所有的1在第一个2之前输出即可,其他元素位置不变,还要考虑当2的数量为0的时候
 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char s[];
while(~scanf("%s",s))
{
int k,ans=,t,ans2=,ans1=;
k=strlen(s);
for(int i=; i<k; i++)
{
if(s[i]=='')
ans++;
if(s[i]=='')
ans2++;
if(s[i]=='')
ans1++;
}//统计0,1,2的数量
for(int i=; i<k; i++)
{
if(s[i]=='')
{
t=i;
break;
}//找到第一个2的位置
}
if(ans1>)//如果2的数量大于0
{
for(int i=; i<k; i++)
{
if(i==t)//在第一个2之前输出所有的1
{
for(int j=; j<=ans; j++)
{
printf("");
}
}
if(s[i]=='')
continue;
else
printf("%c",s[i]);//其他元素照样输出除了1
}
}
else//当2的数量为0的时候
{
for(int i=; i<ans2; i++)
printf("");
for(int i=; i<ans; i++)
printf("");
}
printf("\n");
}
return ;
}

2018SDIBT_国庆个人第一场的更多相关文章

  1. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  2. 校省选赛第一场C题解Practice

    比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...

  3. 校省选赛第一场A题Cinema题解

    今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...

  4. 计蒜之道 初赛第一场B 阿里天池的新任务(简单)

    阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 首先,定义一个序列 ww: \displ ...

  5. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  6. Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)

    Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...

  7. 2018牛客暑期ACM多校训练营第一场(有坑未填)

    (重新组队后的第一场组队赛 也是和自己队友的一次磨合吧 这场比赛真的算是一个下马威吧……队友上手一看 啊这不是莫队嘛 然后开敲 敲完提交发现t了 在改完了若干个坑点后还是依然t(真是一个悲伤的故事)然 ...

  8. 比赛总结——牛客网 NOIP赛前集训营提高组模拟第一场

    第一场打的很惨淡啊 t1二分+前缀最小值没想出来,20分的暴力也挂了,只有10分 t2数位dp,调了半天,结果因为忘了判0的特殊情况WA了一个点,亏死 t3emmmm.. 不会 imone说是DSU ...

  9. NOI.AC NOIP模拟赛 第一场 补记

    NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...

随机推荐

  1. Ajax中最有名axios插件(只应用于Ajax)(post方法,官网写错了,应是字符串格式)

    /* axios v0.18.0 | (c) 2018 by Matt Zabriskie */!function(e,t){"object"==typeof exports&am ...

  2. WebSocket 启用压缩

    m_client.Compression = CompressionMethod.Deflate;

  3. 数据迁移_把RAC环境备份的数据,恢复到另一台单机Oracle本地文件系统下

    数据迁移_把RAC环境备份的数据,恢复到另一台单机Oracle本地文件系统下 作者:Eric 微信:loveoracle11g 1.创建pfile文件 # su - ora11g # cd $ORAC ...

  4. Codeforces-Educational Codeforces Round 53题解

    写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya a ...

  5. 第11章 拾遗4:IPv6(3)_配置IPv6路由

    5. 配置IPv6路由 5.1 配置IPv6静态路由 (1)在路由器上配置静态路由(以R1路由器为例) //静态路由 R1#config t R1(config)#ipv6 unicast-routi ...

  6. C# 委托在线程与UI界面之间的应用

    前景:我们在使用线程的时候,经常会想要访问到Form窗体的控件,也就是线程与UI界面交互,但是他们隶属于连个不同的线程,所以是不能直接访问的,这个时候我们就可以通过委托来实现.打个比方,你想要给远方的 ...

  7. python re模块和collections

    re模块下的常用方法 import re ret = re.findall('a', 'eva egon yuan') # 返回所有满足匹配条件的结果,放在列表里 print(ret) #结果 : [ ...

  8. Java 7-Java 循环结构 - for, while 及 do…while

    Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...

  9. linux设置服务器时间同步

    yum install -y rdate 服务器请设置 */5 * * * * /usr/bin/rdate -s time-b.nist.gov ubuntu 设定时区:dpkg-reconfigu ...

  10. linux学习思维导图(转)

    转自:https://blog.csdn.net/m1585761297/article/details/80017111 先附上一张学习路径的导图 导图一 导图二(一套) 1.Linux目录结构 2 ...