Codeforces Round #251 (Div. 2) A/B/D

Devu和他弟弟喜欢玩数组。他们分别得到了两个数组,Devu的目标是使他的数组中最小值至少等于他弟弟数组中的最大值。通过执行多次操作,即增加或减少数组元素的值,找到满足条件所需的最小操作次数。

A。水题。

A. Devu, the Singer and Churu, the Joker
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.

Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.

The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.

People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.

You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:

  • The duration of the event must be no more than d minutes;
  • Devu must complete all his songs;
  • With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.

If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.

Input

The first line contains two space separated integers nd (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).

Output

If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.

Sample test(s)
input
3 30
2 2 1
output
5
input
3 20
2 1 1
output
-1
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7f3f3ff
#define PI 3.1415926535898


const int maxn = 10010;

using namespace std;

int main()
{
    int n, d;
    while(cin >>n>>d)
    {
        int sum = 0;
        int x;
        for(int i = 1; i <= n; i++)
        {
            cin >>x;
            sum += x;
        }
        sum += (n-1)*10;
        if(sum <= d)
        {
            int t = (n-1)*2+(d-sum)/5;
            cout<<t<<endl;
        }
        else
            cout<<"-1"<<endl;
    }
    return 0;
}

B.注意数据类型啊,int*int即使你用long long 存,也是int、、然后就悲剧了啊、、细节啊

B. Devu, the Dumb Guy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 in x 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 nx (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 test(s)
input
2 3
4 1
output
11
input
4 2
5 1 2 1
output
10
input
3 3
1 1 1
output
6
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7f3f3ff
#define PI 3.1415926535898


const int maxn = 1000010;

using namespace std;

LL num[maxn];

int main()
{
    LL n, m;
    while(cin >>n>>m)
    {
        for(int i = 0; i < n; i++)
            cin >>num[i];
        sort(num, num+n);
        LL cnt = 0;
        for(int i = 0; i < n; i++)
        {
            cnt += num[i]*m;
            if(m > 1)
                m--;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

D。这只能说是太年轻啊、、、终于遇见了会的题目了啊,感觉什么都没问题,无奈三分怎么写都不对,后来发现要牵扯到实数的枚举啊、、发现了两个函数:

floor 功 能: 返回小于或者等于指定表达式的最大整数 用 法: double floor(double x) 

ceil  功 能: 返回大于或者等于指定表达式的最小整数  用法:  double ceil(double x);

D. Devu and his Brother
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and bby their father. The array a is given to Devu and b to his brother.

As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.

Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.

You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.

Input

The first line contains two space-separated integers nm (1 ≤ n, m ≤ 105). The second line will contain n space-separated integers representing content of the array a (1 ≤ ai ≤ 109). The third line will contain m space-separated integers representing content of the array b (1 ≤ bi ≤ 109).

Output

You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.

Sample test(s)
input
2 2
2 3
3 5
output
3
input
3 2
1 2 3
3 4
output
4
input
3 2
4 5 6
1 2
output
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-4
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7ffffff
#define PI 3.1415926535898


const int maxn = 1000010;

using namespace std;

int f[maxn];
int p[maxn];
int n, m;

LL Count(int x)
{
    LL cnt = 0;
    for(int i = 0; i < n; i++)
        if(f[i] < x)
            cnt += x-f[i];
    for(int i = 0; i < m; i++)
        if(p[i] > x)
            cnt += p[i]-x;
    return cnt; 
}

int main()
{
    while(cin >>n>>m)
    {
        for(int i = 0; i < n; i++)
            cin >>f[i];
        for(int i = 0; i < m; i++)
            cin >>p[i];
        LL sum = 1e18;
        LL cnt, cnt1;
        double l = 1;
        double r = 1e9;
        while(l < r-eps)
        {
            double lmid = l+(r-l)/3;
            double rmid = r-(r-l)/3;
            cnt = Count(floor(lmid));// 返回小于或者等于指定表达式的最大整数
            cnt1 = Count(ceil(rmid));//返回大于或者等于指定表达式的最小整数
            if(cnt < cnt1)
                r = rmid;
            else
                l = lmid;
            sum = min(cnt, min(sum, cnt1));
        }
        cout<<sum<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值