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.

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

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

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t,k,d;
while(scanf("%d%d%d%d",&n,&t,&k,&d)!=EOF)
{
int t1;
if(n%k==)
t1=n/k*t;
else t1=(n/k+)*t;
int t2=d+t;
if(t2<t1)
printf("YES\n");
else printf("NO\n");
}
return ;
}

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

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

下面给出AC代码:

 #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,m;
int flag[];
class A
{
public: int id,p;
int operator()(A a,A b)
{
return a.p>b.p;
}
};
priority_queue<A,vector<A>,A> q1,q2,q3;
int a[],b[],c[];
void init()
{
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",a+i);
for(int i=;i<=n;i++)
scanf("%d",b+i);
for(int i=;i<=n;i++)
scanf("%d",c+i);
}
int main()
{
init();
A t;
for(int i=;i<=n;i++)
{
t.id=i;t.p=a[i];
if(b[i]== || c[i]==)
q1.push(t);
if(b[i]== || c[i]==)
q2.push(t);
if(b[i]== || c[i]==)
q3.push(t);
}
cin>>m;
int k;
while(m--)
{
scanf("%d",&k);
int f=;
if(k==)
{
while(q1.size())
{
t=q1.top();q1.pop();
if(flag[t.id]==)
{
flag[t.id]=;
f=;
break;
}
}
}
else if(k==)
{
while(q2.size())
{
t=q2.top();q2.pop();
if(flag[t.id]==)
{
flag[t.id]=;f=;break;
}
}
}
else
{
while(q3.size())
{
t=q3.top();q3.pop();
if(flag[t.id]==)
{
flag[t.id]=;
f=;
break;
}
}
}
if(f)
printf("%d ",t.p);
else
printf("%d ",-);
}
return ;
}

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.

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

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

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

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

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

分析:乱搞一下就可以了

下面给出AC代码:

 #include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node
{
int p,b;
}cc[],dd[];
int dp[][];
int cmp(node a,node b)
{
return a.b<b.b;
}
int main()
{
int n,c,d,p,b,i,j;
int nc=,nd=;
char ch;
cin>>n>>c>>d;
for(i=;i<n;i++)
{
scanf("%d %d %c",&p,&b,&ch);//这个地方故意把p和b反过来了。。懒得改了
node t;
t.b=b;
t.p=p;
if(ch=='C')
{
cc[nc++]=t;
}
else
{
dd[nd++]=t;
}
}
sort(cc,cc+nc,cmp);
sort(dd,dd+nd,cmp);
node t;
t.b=;
t.p=;
cc[nc]=dd[nd]=t;
int ans=;
for(i=;i<nc;i++)
{ int last=c-cc[i].b;
if(last>)
{
if(last>=cc[i].b)
{
if(dp[][cc[i].b]!=)
{
ans=max(ans,dp[][cc[i].b]+cc[i].p);
}
}
else
{
if(dp[][last]!=)
ans=max(ans,dp[][last]+cc[i].p);
}
}
for(j=cc[i].b;j<=cc[i+].b;j++)
{
dp[][j]=max(max(dp[][j],dp[][j-]),cc[i].p);
}
}
for(i=;i<nd;i++)
{ int last=d-dd[i].b;
if(last>)
{
if(last>=dd[i].b)
{
if(dp[][dd[i].b]!=)
ans=max(ans,dp[][dd[i].b]+dd[i].p);
}
else
{
if(dp[][last]!=)
ans=max(ans,dp[][last]+dd[i].p);
}
}
for(j=dd[i].b;j<=dd[i+].b;j++)
{
dp[][j]=max(max(dp[][j],dp[][j-]),dd[i].p);
}
}
if(ans==&&(dp[][c]==||dp[][d]==))
cout<<""<<endl;
else
{
if(dp[][c]!=&&dp[][d]!=)
ans=max(ans,dp[][c]+dp[][d]);
cout<<ans<<endl;
}
return ;
}

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

  1. C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)

    题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...

  2. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】

    题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...

  3. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生

    我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...

  4. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树

    E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...

  5. 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...

  6. 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...

  7. 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)

    http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100  ...

随机推荐

  1. iOS 字体设置,字体类型展示

    字体设置: [UIFont fontWithName:@"Helvetica" size:17.0]]; 字体名字,如图 UIFont fontWithName 后不知道字体的名字 ...

  2. iOS 友盟推送,应用内推送启动图推送闪动黑屏,插屏推送方法报错

    以前都是用的极光推送,应公司需求要求使用友盟推送,为了以后是有分享都适用,,, 友盟推送文档,下载demo 感觉比极光用着要简单顺手 一切就绪后,开始发送消息测试,,,,,搞了半天没有发过来消息 原来 ...

  3. iOS APP内购

    看到网上文章一大把,看了这个觉得挺不错的,谢谢 iOS大全 公众平台; 原文:http://mp.weixin.qq.com/s?__biz=MzAxMzE2Mjc2Ng==&mid=2652 ...

  4. mouseout、mouseover和mouseleave、mouseenter区别

    今天在使用鼠标事件时,用错了mouseout,于是做个测试总结. 结论: mouseenter:当鼠标移入某元素时触发. mouseleave:当鼠标移出某元素时触发. mouseover:当鼠标移入 ...

  5. 【原码笔记】-- protobuf.js 与 Long.js

    protobuf.js的结构和webpack的加载之后的结构很相似.这样的模块化组合是个不错的结构方式.1个是适应了不同的加载方式,2个模块直接很独立.webpack的功能更全一点.但如果自己封装js ...

  6. Vue入门总结

    技术栈:VUE:Vue-router:Vue-resource:Vue-cli: 项目:个人博客vue重构 一.vue-cli脚手架搭建项目结构 全局安装vue-cli: npm install vu ...

  7. Mac下nvm管理node.js版本问题

    本篇文章主要是针对已经安装了node.js和nvm管理工具小伙伴遇到的问题. 管理工具有两个,一个是nvm,还有一个是nnvm的好处就是可以管理多个node版本,而且可以切换想要的版本,可以安装一个稳 ...

  8. solr安装配置

    1.solr是基于tomcat安装部署的 2.网上下载solr-5.2.1 http://lucene.apache.org/solr/downloads.html 3.解压solr文件 tar zx ...

  9. js遍历 子节点 子元素

    Js 节点 子元素 属性 方法 // 添加子节点前 删除所有子节点 var usernameEle = document.getElementById("username"); v ...

  10. Java语言的概述?-什么是Java? (附一张Java工程师的学习路线图)

    什么是Java? Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态面向 ...