前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

作者头像
Angel_Kitty
发布2018-04-09 10:44:18
1.1K0
发布2018-04-09 10:44:18
举报
文章被收录于专栏:小樱的经验随笔

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

代码语言:javascript
复制
8 6 4 5

Output

代码语言:javascript
复制
YES

Input

代码语言:javascript
复制
8 6 4 6

Output

代码语言:javascript
复制
NO

Input

代码语言:javascript
复制
10 3 11 4

Output

代码语言:javascript
复制
NO

Input

代码语言:javascript
复制
4 2 1 4

Output

代码语言:javascript
复制
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.

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

分析:计算 不造第二台需要的时间还有造出第二台 做出一个蛋糕需要的时间  如果小于第一台需要的总时间 则YES

下面给出AC代码:

代码语言:javascript
复制
 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

代码语言:javascript
复制
5 
300 200 400 500 911 
1 2 1 2 3 
2 1 3 2 1 
6 
2 3 1 2 1 1

Output

代码语言:javascript
复制
200 400 300 500 911 -1 

Input

代码语言:javascript
复制
2 
1000000000 1 
1 1 
1 2 
2 
2 1

Output

代码语言:javascript
复制
1 1000000000 

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

分析:每人选择一件衣服  价钱最小的而且颜色有一面是自己喜欢的,用优先队列做的,看看就好

下面给出AC代码:

代码语言:javascript
复制
 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

代码语言:javascript
复制
3 7 6 
10 8 C 
4 3 C 
5 6 D

Output

代码语言:javascript
复制
9

Input

代码语言:javascript
复制
2 4 5 
2 5 C 
2 1 D

Output

代码语言:javascript
复制
0

Input

代码语言:javascript
复制
3 10 10 
5 5 C 
5 5 C 
10 11 D

Output

代码语言:javascript
复制
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.

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

题意:你有两种货币,每种只能买相应的东西,给了n个喷泉,每个喷泉有个漂亮值和价格以及你能用哪种货币买,

问用已拥有的货币你买两个喷泉,最大漂亮值多少

必须要买两个,买不起两个就是0

价格的范围很小,可以开个数组dp【i】记录i货币可以买的最大价值

分析:乱搞一下就可以了

下面给出AC代码:

代码语言:javascript
复制
 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      }  
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-05-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A. Carrot Cakes
  • B. T-shirt buying
  • C. Fountains
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档