codeforces#357 前三题题解

A. A Good Contest

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.

Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.

Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest .

The next n lines describe participants results: i-th} of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.

It is guaranteed that all handles are distinct.

Output

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

Examples

Input

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

Output

YES

Input

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

Output

NO

Note

In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.

In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.



A.题目大意:给你n个人,接下来n行输入人名和这一场比赛之前的分数和之后的分数,根据规定,大于等于2400分的选手是红色的名字,问这n个人中是否有在比赛前就红色名字并且比赛之后还是红色名字并且涨分了的人。

思路:直接按照中文题意简单水一发.

AC代码:

#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int fla=0;
        for(int i=0;i<n;i++)
        {
            char a[100];
            int b,c;
            scanf("%s%d%d",a,&b,&c);
            if(b>=2400&&c>=2400&&c>b)fla=1;
        }
        if(fla==1)
        {
            printf("YES\n");
        }
        else printf("NO\n");
    }
}


B. Economy Game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.

Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).

Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?

Please help Kolya answer this question.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin score.

Output

Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).

Examples

Input

1359257

Output

YES

Input

17851817

Output

NO

Note

In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.

 




B.题目大意:给你一个数n,问你这个数n能否用这样的式子来表示出来:n==1234567*a+123456*b+1234*c


思路:因为n最大是10^9,如果我们三层for分别枚举a,b,c是非常尴尬的一个超时状态,所以我们这里应用一个小小的技巧就能避免掉超时的尴尬情况。
设d=n-(1234567*a+123456*b)如果d%1234==0那么n就一定是能够用上述式子表达出来的,如果不能整除,继续枚举a和b,这里注意一个点,如果d是负数,要跳出循环。

AC代码:

#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        for(int i=0;i<100;i++)
        {
            for(int j=0;j<1000;j++)
            {
                if(n-(i*1234567+j*123456)<0)break;
                if((n-(i*1234567+j*123456))%1234==0)
                {
                    flag=1;
                    break;
                }
            }
            if(flag==1)break;
        }
        if(flag==1)printf("YES\n");
        else printf("NO\n");
    }
}

C. Heap Operations

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya has recently learned data structure named "Binary heap".

The heap he is now operating with allows the following operations:

· put the given number into the heap;

· get the value of the minimum element in the heap;

· extract the minimum element from the heap;

Thus, at any moment of time the heap contains several integers (possibly none), some of them might be equal.

In order to better learn this data structure Petya took an empty heap and applied some operations above to it. Also, he carefully wrote down all the operations and their results to his event log, following the format:

· insert x — put the element with value x in the heap;

· getMin x — the value of the minimum element contained in the heap was equal to x;

· removeMin — the minimum element was extracted from the heap (only one instance, if there were many).

All the operations were correct, i.e. there was at least one element in the heap each time getMin or removeMin operations were applied.

While Petya was away for a lunch, his little brother Vova came to the room, took away some of the pages from Petya's log and used them to make paper boats.

Now Vova is worried, if he made Petya's sequence of operations inconsistent. For example, if one apply operations one-by-one in the order they are written in the event log, results of getMin operations might differ from the results recorded by Petya, and some of getMin or removeMin operations may be incorrect, as the heap is empty at the moment they are applied.

Now Vova wants to add some new operation records to the event log in order to make the resulting sequence of operations correct. That is, the result of each getMin operation is equal to the result in the record, and the heap is non-empty when getMin ad removeMin are applied. Vova wants to complete this as fast as possible, as the Petya may get back at any moment. He asks you to add the least possible number of operation records to the current log. Note that arbitrary number of operations may be added at the beginning, between any two other operations, or at the end of the log.

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 100 000) — the number of the records left in Petya's journal.

Each of the following n lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers not exceeding 109 by their absolute value.

Output

The first line of the output should contain a single integer m — the minimum possible number of records in the modified sequence of operations.

Next m lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applied. All the numbers in the output should be integers not exceeding 109 by their absolute value.

Note that the input sequence of operations must be the subsequence of the output sequence.

It's guaranteed that there exists the correct answer consisting of no more than 1 000 000 operations.

Examples

Input

2
insert 3
getMin 4

Output

4
insert 3
removeMin
insert 4
getMin 4

Input

4
insert 1
insert 1
removeMin
getMin 2

Output

6
insert 1
insert 1
removeMin
removeMin
insert 2
getMin 2

Note

In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.

In the second sample case number 1 is inserted two times, so should be similarly removed twice.

 

题目大意:题干真他喵的长,读起来很难受,题目大意是这样的,给出n个操作语句,来模拟最小堆的三种操作:
1、insert x 表示向堆内加入一个元素x
2、removeMin 表示移除堆顶元素
3、getMin x 表示在堆中找到x这个元素。
然后将输入不正确的地方,进行修改,输出修改后的操作数,和各种操作。
思路:优先队列模拟最小堆,对于三种操作:

1、insert x的时候,直接入队x即可
2、removeMin的时候,记住先判断队列是否为空(堆是否为空),如果不为空,直接弹出对头元素即可。如果为空,注意原题中有这样一句话:
Note that the input sequence of operations must be the subsequence of the output sequence.
所以如果队列为空,我们可以任意向队列中加入一个元素之后,再将这个元素弹出。
3、getMin的时候,分三种情况讨论,一种是队头就是x,一种是队头比x大,一种是队头比x小,如果队头就是x,那么直接输出得到了这个数就行。如果队头比x大,那么直接入队x即可,如果队头比x小,那么应该先把这个小的数弹出,一直弹到队列为空或者是队头元素大于等于x的时候,再入队x即可。

因为输出第一个值为修改后的总操作数,所以我的代码写的有点挫,求担待.....
注意的点:

1、千万注意不要在队列空的时候pop,要不然会Re


2、getMin操作不需要pop操作的跟随。



AC代码:


#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
char a[200005][250];
int xx[200005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        priority_queue<int,vector<int>,greater <int > >s;
        memset(xx,0,sizeof(xx));
        for(int i=0;i<n;i++)
        {
            scanf("%s",a[i]);
            if(a[i][0]!='r')
            scanf("%d",&xx[i]);
        }
        int output=0;
        for(int i=0;i<n;i++)
        {
            char op[100];
            strcpy(op,a[i]);
            int x=xx[i];
            if(op[0]=='i')
            {
                s.push(x);
                output++;
            }
            if(op[0]=='r')
            {
                if(s.size()>0)
                {
                    s.pop();
                    output++;
                }
                else
                {
                    output++;output++;
                }
            }
            if(op[0]=='g')
            {
                int flag=0;
                while(!s.empty())
                {
                    int now=s.top();
                    if(now==x)
                    {
                        //s.pop();
                        output++;
                        flag=1;
                    }
                    if(now>x)
                    {
                        output++;
                        s.push(x);
                        output++;
                        flag=1;
                    }
                    if(now<x)
                    {
                        s.pop();
                        output++;
                    }
                    if(flag==1)break;
                }
                if(flag==0)
                {
                    output++;
                    s.push(x);
                    output++;
                }
            }
        }
        printf("%d\n",output);
        while(!s.empty())s.pop();
        for(int i=0;i<n;i++)
        {
            char op[250];
            int x=0;
            strcpy(op,a[i]);
            if(op[0]!='r')
            x=xx[i];
            if(op[0]=='i')
            {
                s.push(x);
                printf("insert %d\n",x);
            }
            if(op[0]=='r')
            {
                if(s.size()>0)
                {
                    s.pop();
                    printf("removeMin\n");
                }
                else
                {
                    printf("insert 0\n");
                    printf("removeMin\n");
                }

            }
            if(op[0]=='g')
            {
                int flag=0;
                while(!s.empty())
                {
                    int now=s.top();
                    if(now==x)
                    {
                       // s.pop();
                        printf("getMin %d\n",x);
                        flag=1;
                    }
                    if(now>x)
                    {
                        printf("insert %d\n",x);
                        s.push(x);
                        printf("getMin %d\n",x);
                        flag=1;
                    }
                    if(now<x)
                    {
                        s.pop();
                        printf("removeMin\n");
                    }
                    if(flag==1)break;
                }
                if(flag==0)
                {
                    printf("insert %d\n",x);
                    s.push(x);
                    printf("getMin %d\n",x);
                }
            }
        }
    }
}




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值