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. 【python】字符串变量赋值时字符串可用单或双引号

    >>> name='萧峰' >>> print(name) 萧峰 >>> name="独孤求败" >>> p ...

  2. Noip2016换教室(期望+DP)

    Description 题目链接:Luogu Solution 这题结合了DP和概率与期望,其实只要稍微知道什么是期望就可以了, 状态的构造很关键,\(F[i][j][0/1]\)表示已经到第\(i\ ...

  3. Linux中dos2unix批量转换

    有时候遇到多层目录下的文件格式需要转换,dos2unix 没有-r之类的递归指令,所以需要与find还有管道结合. find -type f | xargs dos2unix -o

  4. Smart line Panel和S7-200的MPI通信

    1.系统组成 2.一个简单任务 3.设置S7-200的通信参数 1)新建工程,设置CPU类型 2)设置端口1的通讯参数PLC地址为2,波特率187.5kbps 组态 3)保存完成配置 4.组态Smar ...

  5. mysql TIMESTAMP与DATATIME的区别---转载加自己的看法

    from:http://lhdeyx.blog.163.com/blog/static/318196972011230113645715/ from:http://blog.csdn.NET/zht6 ...

  6. DataInputStream EOFEXCEPTION

    在编写socket通信时,服务端使用了DataInputStream.readUTF()读取字节流时,出现EOFEXCEPTION 原因是客户端没有使用DataOutputStream.writeUT ...

  7. Optimize For Ad Hoc Workloads

    --临时工作负载优化   即席查询:也就是查询完没放到Cache当中,每次查询都要重新经过编译,并发高的时候很耗性能: 参数化查询: 一方面解决了重编译问题,但随着数据库数据数据的变更,统计信息的更新 ...

  8. Go基础之--结构体和方法

    结构体的定义 结构体是将零个或者多个任意类型的命令变量组合在一起的聚合数据类型.每个变量都叫做结构体的成员. 其实简单理解,Go语言的结构体struct和其他语言的类class有相等的地位,但是GO语 ...

  9. ECMAScript 6新特性简记

    ECMAScript 6.0是JavaScript语言的2015年6月的发布版. 一.let和const命令 let:用来声明变量,用法类似于var,但是只在let命令所在的代码块内有效. var a ...

  10. Koa2和相关资料

    koa2是什么我就不介绍,这里只是收集一些有用的资料,koa这里默认就指koa2了额. koa介绍 koa(GitHub) koa(npm) 文档 Usage Guide Error Handling ...