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. 数据分析与展示——Pandas数据特征分析

    Pandas数据特征分析 数据的排序 将一组数据通过摘要(有损地提取数据特征的过程)的方式,可以获得基本统计(含排序).分布/累计统计.数据特征(相关性.周期性等).数据挖掘(形成知识). .sort ...

  2. JavaWeb 例子 JDBC+JSP登陆注册留言板

    注册页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  3. iOS App3D Touch快捷键的静态以及动态设置详细使用

    1. 功能支持 3D-Touch 只在 iOS 9 及以上版本得到支持,之前版本的 iOS 并不支持该功能:3D-Touch 只在 iPhone 6s 及以后型号的 iPhone 或 iPad Pro ...

  4. 点击button1弹出form2,并在form2中点击button2来调用form1的方法

    链接地址:http://www.sufeinet.com/thread-1273-1-1.html   1.     private void button1_Click(object sender, ...

  5. jQueryUI Autocomplete插件使用入门教程(最新版)---------转载

    前言: jQuery,无需多作介绍,相信各位读者都应该接触或使用过了.jQuery UI,简而言之,它是一个基于jQuery的前端UI框架.我们可以使用jQuery + jQuery UI非常简单方便 ...

  6. 了解数组中的队列方法,DOM中节点的一些操作

    队列的概念 栈是一种后进先出的结构,而队列是一种先进先出的结构.如银行排队,排在前面的人先办业务然后离开,后来的人站在最后.可以用队列的push()方法插入元素到队列的末尾,可以用shift()方法删 ...

  7. C/C++调用Golang 二

    C/C++调用Golang 二 <C/C++调用Golang 一>简单介绍了C/C++调用Golang的方法步骤,只涉及一个简单的函数调用.本文总结具体项目中的使用场景,将介绍三种较复杂的 ...

  8. Python 项目实践三(Web应用程序)第三篇

    接着上节的继续学习,现在要显示所有主题的页面 有了高效的网页创建方法,就能专注于另外两个网页了:显示全部主题的网页以及显示特定主题中条目的网页.所有主题页面显示用户创建的所有主题,它是第一个需要使用数 ...

  9. [编织消息框架][netty源码分析]9 Promise 实现类DefaultPromise职责与实现

    netty Future是基于jdk Future扩展,以监听完成任务触发执行Promise是对Future修改任务数据DefaultPromise是重要的模板类,其它不同类型实现基本是一层简单的包装 ...

  10. 例子:韩顺平JavaScript----JS乌龟抓小鸡游戏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...