# A. Carrot Cakes

time limit per test：1 second

memory limit per test：256 megabytes

input：standard input

output：standard output

In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.

Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.

Input

The only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven.

Output

If it is reasonable to build the second oven, print "YES". Otherwise print "NO".

Examples

Input

`8 6 4 5`

Output

`YES`

Input

`8 6 4 6`

Output

`NO`

Input

`10 3 11 4`

Output

`NO`

Input

`4 2 1 4`

Output

`YES`

Note

In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.

In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.

In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.

``` 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5     int n,t,k,d;
6     while(scanf("%d%d%d%d",&n,&t,&k,&d)!=EOF)
7     {
8         int t1;
9         if(n%k==0)
10             t1=n/k*t;
11         else t1=(n/k+1)*t;
12         int t2=d+t;
13         if(t2<t1)
14             printf("YES\n");
15         else printf("NO\n");
16     }
17     return 0;
18 }```

# B. T-shirt buying

time limit per test：3 seconds

memory limit per test：256 megabytes

input：standard input

output：standard output

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.

m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.

A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.

You are to compute the prices each buyer will pay for t-shirts.

Input

The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.

The following line contains sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt.

The following line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt.

The following line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt.

The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.

The following line contains sequence c1, c2, ..., cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

Output

Print to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won't buy anything, print -1.

Examples

Input

```5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1```

Output

`200 400 300 500 911 -1 `

Input

```2
1000000000 1
1 1
1 2
2
2 1```

Output

`1 1000000000 `

题目链接：http://codeforces.com/contest/799/problem/B

``` 1 #include <bits/stdc++.h>
2 typedef long long ll;
3 using namespace std;
4 int n,m;
5 int flag[200200];
6 class A
7 {
8     public: int id,p;
9     int operator()(A a,A b)
10     {
11         return a.p>b.p;
12     }
13 };
14 priority_queue<A,vector<A>,A> q1,q2,q3;
15 int a[200200],b[200200],c[200200];
16 void init()
17 {
18     cin>>n;
19     for(int i=1;i<=n;i++)
20         scanf("%d",a+i);
21     for(int i=1;i<=n;i++)
22         scanf("%d",b+i);
23     for(int i=1;i<=n;i++)
24         scanf("%d",c+i);
25 }
26 int main()
27 {
28     init();
29     A t;
30     for(int i=1;i<=n;i++)
31     {
32         t.id=i;t.p=a[i];
33         if(b[i]==1 || c[i]==1)
34             q1.push(t);
35         if(b[i]==2 || c[i]==2)
36             q2.push(t);
37         if(b[i]==3 || c[i]==3)
38             q3.push(t);
39     }
40     cin>>m;
41     int k;
42     while(m--)
43     {
44         scanf("%d",&k);
45         int f=0;
46         if(k==1)
47         {
48             while(q1.size())
49             {
50                 t=q1.top();q1.pop();
51                 if(flag[t.id]==0)
52                 {
53                     flag[t.id]=1;
54                     f=1;
55                     break;
56                 }
57             }
58         }
59         else if(k==2)
60         {
61             while(q2.size())
62             {
63                 t=q2.top();q2.pop();
64                 if(flag[t.id]==0)
65                 {
66                     flag[t.id]=1;f=1;break;
67                 }
68             }
69         }
70         else
71         {
72             while(q3.size())
73             {
74                 t=q3.top();q3.pop();
75                 if(flag[t.id]==0)
76                 {
77                     flag[t.id]=1;
78                     f=1;
79                     break;
80                 }
81             }
82         }
83         if(f)
84             printf("%d ",t.p);
85         else
86             printf("%d ",-1);
87     }
88     return 0;
89 }```

# C. Fountains

time limit per test：2 seconds

memory limit per test：256 megabytes

input：standard input

output：standard output

Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.

Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.

Input

The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.

The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.

Output

Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.

Examples

Input

```3 7 6
10 8 C
4 3 C
5 6 D```

Output

`9`

Input

```2 4 5
2 5 C
2 1 D```

Output

`0`

Input

```3 10 10
5 5 C
5 5 C
10 11 D```

Output

`10`

Note

In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.

In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.

``` 1 #include<bits/stdc++.h>
2     typedef long long ll;
3     using namespace std;
4     struct node
5     {
6         int p,b;
7     }cc[100050],dd[100050];
8     int dp[2][100050];
9     int cmp(node a,node b)
10     {
11         return a.b<b.b;
12     }
13     int main()
14     {
15         int n,c,d,p,b,i,j;
16         int nc=0,nd=0;
17         char ch;
18         cin>>n>>c>>d;
19         for(i=0;i<n;i++)
20         {
21             scanf("%d %d %c",&p,&b,&ch);//这个地方故意把p和b反过来了。。懒得改了
22             node t;
23             t.b=b;
24             t.p=p;
25             if(ch=='C')
26             {
27                 cc[nc++]=t;
28             }
29             else
30             {
31                 dd[nd++]=t;
32             }
33         }
34         sort(cc,cc+nc,cmp);
35         sort(dd,dd+nd,cmp);
36         node t;
37         t.b=100005;
38         t.p=0;
39         cc[nc]=dd[nd]=t;
40         int ans=0;
41         for(i=0;i<nc;i++)
42         {
43
44             int last=c-cc[i].b;
45             if(last>0)
46             {
47                 if(last>=cc[i].b)
48                 {
49                     if(dp[0][cc[i].b]!=0)
50                     {
51                         ans=max(ans,dp[0][cc[i].b]+cc[i].p);
52                     }
53                 }
54                 else
55                 {
56                     if(dp[0][last]!=0)
57                     ans=max(ans,dp[0][last]+cc[i].p);
58                 }
59             }
60             for(j=cc[i].b;j<=cc[i+1].b;j++)
61             {
62                 dp[0][j]=max(max(dp[0][j],dp[0][j-1]),cc[i].p);
63             }
64         }
65         for(i=0;i<nd;i++)
66         {
67
68             int last=d-dd[i].b;
69             if(last>0)
70             {
71                 if(last>=dd[i].b)
72                 {
73                     if(dp[1][dd[i].b]!=0)
74                     ans=max(ans,dp[1][dd[i].b]+dd[i].p);
75                 }
76                 else
77                 {
78                     if(dp[1][last]!=0)
79                     ans=max(ans,dp[1][last]+dd[i].p);
80                 }
81             }
82             for(j=dd[i].b;j<=dd[i+1].b;j++)
83             {
84                 dp[1][j]=max(max(dp[1][j],dp[1][j-1]),dd[i].p);
85             }
86         }
87         if(ans==0&&(dp[0][c]==0||dp[1][d]==0))
88         cout<<"0"<<endl;
89         else
90         {
91             if(dp[0][c]!=0&&dp[1][d]!=0)
92             ans=max(ans,dp[0][c]+dp[1][d]);
93             cout<<ans<<endl;
94         }
95         return 0;
96      }  ```

0 条评论

• ### Code forces 719A Vitya in the Countryside

A. Vitya in the Countryside time limit per test:1 second memory limit per test:2...

• ### Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

A. Combination Lock time limit per test：2 seconds memory limit per test：256 mega...

• ### Codeforces Round #300(A.【字符串，多方法】，B.【思维题】，C.【贪心,数学】)

A. Cutting Banner time limit per test：2 seconds memory limit per test：256 megaby...

• ### 【CodeForces 602C】H - Approximating a Constant Range（dijk）

In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional rai...

• ### Ceph用户邮件列表Vol45-Issue3

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=af5e5...

• ### IOS5开发-控件位置适应屏幕旋转代码

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation  ...

• ### 周练19.11.03/10

它表示一个迷宫，其中的1表示墙壁，0表示可以走的路，只能横着走或竖着走，不能斜着走，要求编程序找出从左上角到右下角的最短路线。

• ### 多语言姿态检测：加泰罗尼亚独立语料库(CS.CL)

姿态检测旨在确定给定文本相对于特定主题或主张的态度。尽管最近几年对姿势检测进行了很好的研究，但大多数工作都集中在英语上。这主要是由于其他语言中相对缺少带注释的数...

• ### 机器人控制器编程课程-教案02-基础

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。