codeforces/problem/175/C 贪心
2014-02-06 15:17
204 查看
C. Geometry Horse
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya plays the Geometry Horse.
The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.
There are n types of geometric figures. The number of figures of type ki and
figure cost ci is
known for each figure type. A player gets ci·fpoints
for destroying one figure of type i, where f is
the current factor. The factor value can be an integer number from 1 to t + 1,
inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 ≤ i ≤ t) figures,
so the (pi + 1)-th
figure to be destroyed is considered with factor equal to i + 1.
Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.
Input
The first line contains the only integer number n (1 ≤ n ≤ 100) —
the number of figure types.
Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000),
separated with space — the number of figures of the i-th type and the cost of one i-type
figure, correspondingly.
The next line contains the only integer number t (1 ≤ t ≤ 100) —
the number that describe the factor's changes.
The next line contains t integer numbers pi (1 ≤ p1 < p2 < ... < pt ≤ 1012),
separated with spaces.
Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams
or the%I64d specificator.
Output
Print the only number — the maximum number of points Vasya can get.
Sample test(s)
input
output
input
output
Note
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and
after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points.
In the second example all 8 figures will be destroyed with factor 1,
so Vasya will get (3·8 + 5·10)·1 = 74 points.
题意;给了n中物品,每种物品数量是ki,价值ci, 摧毁一件东西的收获值是 Ki* Ci * F;
有T个分段点。0-p1 中的东西f=1,摧毁够 pi 件后,f=f+1;
问最大的 收获值;
贪心的想法,ci值越大,留到越后处理,收获值就会越大。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya plays the Geometry Horse.
The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.
There are n types of geometric figures. The number of figures of type ki and
figure cost ci is
known for each figure type. A player gets ci·fpoints
for destroying one figure of type i, where f is
the current factor. The factor value can be an integer number from 1 to t + 1,
inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 ≤ i ≤ t) figures,
so the (pi + 1)-th
figure to be destroyed is considered with factor equal to i + 1.
Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.
Input
The first line contains the only integer number n (1 ≤ n ≤ 100) —
the number of figure types.
Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000),
separated with space — the number of figures of the i-th type and the cost of one i-type
figure, correspondingly.
The next line contains the only integer number t (1 ≤ t ≤ 100) —
the number that describe the factor's changes.
The next line contains t integer numbers pi (1 ≤ p1 < p2 < ... < pt ≤ 1012),
separated with spaces.
Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams
or the%I64d specificator.
Output
Print the only number — the maximum number of points Vasya can get.
Sample test(s)
input
1 5 10 2 3 6
output
70
input
2 3 8 5 10 1 20
output
74
Note
In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and
after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points.
In the second example all 8 figures will be destroyed with factor 1,
so Vasya will get (3·8 + 5·10)·1 = 74 points.
题意;给了n中物品,每种物品数量是ki,价值ci, 摧毁一件东西的收获值是 Ki* Ci * F;
有T个分段点。0-p1 中的东西f=1,摧毁够 pi 件后,f=f+1;
问最大的 收获值;
贪心的想法,ci值越大,留到越后处理,收获值就会越大。
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; struct node { int c,d; void init() { scanf("%d%d",&c,&d); } }a[110]; long long p[110]; bool cmp(node a,node b) { return a.d<b.d; } int main() { // freopen("in.txt","r",stdin); int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) a[i].init(); sort(a,a+n,cmp); int t; scanf("%d",&t); for(int i=1;i<=t;i++) cin>>p[i]; for(int i=t;i>1;i--) p[i]-=p[i-1]; long long ans=0; int st=0; for(int i=1;i<=t;i++) { long long cur=0; while(p[i]>0&&st<n) { if(p[i]>a[st].c){ cur+=1ll*a[st].c*a[st].d; p[i]-=a[st].c; st++; } else{ cur+=p[i]*a[st].d; a[st].c-=p[i]; break; } } ans+=cur*i; } long long cur=0; for(;st<n;st++) cur+=1ll*a[st].c*a[st].d; ans+=cur*(++t); cout<<ans<<endl; } return 0; }
相关文章推荐
- Codeforces Problem 712C Memory and De-Evolution(贪心,逆推)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem (贪心)
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Problem - 37B - Computer Game (贪心、模拟)
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
- Codeforces Round #253 Div2 D.Andrey and Problem 概率+贪心
- CodeForces Far Relative’s Problem (贪心)
- Codeforces Far Relative’s Problem(区间贪心)
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心,二分
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- 【Codeforces Round 365 (Div 2)C】【贪心 极限阻碍思想】 Chris and Road 过马路不被凸包车碰撞的最小时间
- codeforces.com/problemset/problem/213/C
- Codeforces problem 459C Pashmak and Buses
- Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
- Educational Codeforces Round 21 C. Tea Party 贪心
- Codeforces Round #342 (Div. 2) 625A Guest From the Past(贪心)
- codeforces#236_div2_A nuts 贪心
- Codeforces Problem 333A - Secrets