CodeForces 439B Devu, the Dumb Guy
2014-07-14 10:35
399 查看
Devu, the Dumb Guy
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
439B
Description
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject
has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject inx hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more
clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather
than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
Input
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105).
The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).
Output
Output a single integer representing the answer to the problem.
Sample Input
Input
Output
Input
Output
Input
Output
Hint
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours
per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching
him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours
per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours.
Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 hours.
Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours
per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
思路:看懂就明白了 应该注意的是n,x的范围 10e5 说明数据结果可能是个很大的数 所以得用long long 来保存结果(fk话说他哪里来的那么多时间 真是无聊QwQ)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
439B
Description
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject
has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject inx hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more
clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather
than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
Input
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105).
The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).
Output
Output a single integer representing the answer to the problem.
Sample Input
Input
2 3 4 1
Output
11
Input
4 2 5 1 2 1
Output
10
Input
3 3 1 1 1
Output
6
Hint
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours
per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching
him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.
Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours
per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours.
Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.
So overall, minimum of both the cases is 11 hours.
Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours
per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.
思路:看懂就明白了 应该注意的是n,x的范围 10e5 说明数据结果可能是个很大的数 所以得用long long 来保存结果(fk话说他哪里来的那么多时间 真是无聊QwQ)
#include<iostream> #include<algorithm> using namespace std; long long a[100005]; int main() { long long n,m; while(cin>>n>>m) { for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); long long ans=0,k=m; for(int i=0;i<n;i++) { ans+=a[i]*k; if(k!=1) k--; } cout<<ans<<endl; } }
相关文章推荐
- Codeforces 439 B. Devu, the Dumb Guy
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guy
- B. Devu, the Dumb Guy
- Codeforces 439B Devu, the Dumb Guy(贪心)
- Codeforces 439 A. Devu, the Singer and Churu, the Joker
- Codeforces 439B Devu, the Dumb Guy
- CodeForces 439B Devu, the Dumb Guy
- Devu, the Dumb Guy
- Codeforces 439B Devu, the Dumb Guy
- codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
- Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
- Codeforces Round #251(Div. 2) 439B. Devu, the Dumb Guy 贪心
- codeforces—— 439A —— Devu, the Singer and Churu, the Joker
- Codeforces 469A - I Wanna Be the Guy (这俩方法都很好)
- Codeforces 469A I Wanna Be the Guy(水题)
- 【CodeForces】A. I Wanna Be the Guy
- Codeforces 842C Ilya And The Tree【Dfs】
- codeforces 451E. Devu and Flowers 容斥原理+lucas
- codeforces 842C. Ilya And The Tree(dfs)
- I'm the new guy here