Codeforces Round #652 (Div. 2) C. RationalLee 贪心
题意:
t组输入,你有n个数,还有k个朋友,每一个朋友需要wi个数。意思就是你要给第i个朋友分配wi个数,输入保证w1+w2+...+wk=n
一个朋友的兴奋值是你分配给他的数中最大值加上最小值的和(如果某个朋友只有一个数,那最小值和最大值都是一样的)。
题解:
首先对于只需求一个数的朋友,我们应该先处理,给他分配最大的数给他,因为这样这些大数会被加两遍。
然后我们安排剩下的人。我们知道一个人的贡献只和最大值最小值有关,中间那些是什么并不关心,所以我们从拿的最多的那个人开始,因为当前剩下的数中,最小和最大的那两个数肯定是要被计算的,所以我们把这两个数给到这个人,中间的话我们考虑贪心,把剩下尽可能小的数尽可能给他。
代码:
#include <stdio.h>
#include <string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll v[maxn],w[maxn];
int main()
{
ll t;
scanf("%I64d",&t);
while(t--)
{
ll n,k,ans=0;
scanf("%I64d%I64d",&n,&k);
for(ll i=0; i<n; ++i)
{
scanf("%I64d",&v[i]);
}
sort(v, v + n);//����
int t = n-1;
for(ll i=0;i<k;++i)
{
scanf("%I64d",&w[i]);
if(w[i]==1)
{
ans=ans+2*v[t];
//printf("%I64d***\t",ans);
t--;
}
}
// for(int i=0;i<k;++i)
// {
//
// else
// {
// break;
// }
// }
/*
for (int i = 0; i < k; i++)
{
cin >> w[i];
if (w[i] == 1)
{
ans += v[t] * 2;//���Ϊ1������䵱ǰ����ֵ
t--;//�������ֵ���±�
}
}
*/
sort(w, w + k);//����
//int y = k - temp;
int l = 0;
for (int i = k-1; i>=0; i--) //�ȷ���b[i]���ֵ��������ȥ������С��ֵ��
{
if (w[i] != 1)
{
ans = ans + v[t] + v[l];//���ϵ�ǰ��С��ֵ�͵�ǰ����ֵ
l = l + (w[i] - 1);//������Сֵ���±�
t--;//�������ֵ���±�
} }
cout << ans << endl;
/*
for(ll i=0;i<k;++i)
{
scanf("%I64d",&w[i]);
}
sort(v,v+n);
sort(w,w+k);
ll sum=0;
ll start=0,i,j;
n--;
for(i=0;i<k;++i)
{
if(w[i]==1)
{
sum=sum+2*v[n];
//printf("%I64d***\n",sum);
n--;
}
else
{
break;
}
}
for(j=k-1;j>=i;--j)
{
sum=sum+v[start]+v[n];
start+=(w[i]-1);
n--;
}
printf("%I64d\n",sum);
*/
}
return 0;
}
Codeforces Round #652 (Div. 2) C. RationalLee 贪心的更多相关文章
- Codeforces Round #652 (Div. 2) C. RationalLee(贪心)
题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^ ...
- Codeforces Round #652 (Div. 2) E. DeadLee 贪心
题意: 派会上有n种食物,每种食物有wi份.有m个朋友,每一个朋友有两种他喜欢吃的食物xi,yi.你需要判断他的朋友是否都能吃到食物.如果都能吃到食物,那么要输出朋友来的顺序,不能的话输出" ...
- Codeforces Round #652 (Div. 2) E. DeadLee(贪心)
题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友 ...
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
随机推荐
- Docker学习笔记之查看Docker
命令: 使用history命令查看镜像历史 使用cp命令复制容器中的文件到主机 使用commit命令把修改过的容器创建为镜像 使用diff命令检查容器文件的修改 使用inspect命令查看容器/镜像详 ...
- Desired_Capabilities配置
appium服务器初始化参数 最全: https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/caps. ...
- spring cloud gateway 日志打印
从api请求中获取访问的具体信息,是一个很常见的功能,这几天在研究springcloud,使用到了其中的gateway,刚好将研究的过程结果都记录下来 0. Version <parent> ...
- Error: Could not open input file: /usr/java/jdk1.7.0_07/jre/lib/jsse.pack
[root@localhost ~]# rpm -ivh jdk-7u7-linux-i586.rpm Preparing... ################################### ...
- 在项目中应该使用Boolean还是使用boolean?
起因 在公司看代码时,看到了使用Boolean对象来完成业务逻辑判断的操作.和我的习惯不一致,于是引起了一些反思. boolean和Boolean的差别咱就不说了,我们仅探讨使用boolean与Boo ...
- ctfhub技能树—信息泄露—备份文件下载—.DS_Store
打开靶机 查看页面信息 使用dirsearch进行扫描 访问该网页,下载文件 使用Linux系统打开文件 发现一个特殊文件,使用浏览器打开 拿到flag 二.使用Python-dsstore工具查看该 ...
- postgresql数据库升级
pg_upgrade官网介绍:https://www.postgresql.org/docs/10/pgupgrade.html 1.查看老版本数据库编译参数值并记录 select name,sett ...
- Linux更换软件源
1. Ubuntu16.04 sudo cp /etc/apt/sources.list /etc/apt/sources_origin.list # 备份 sudo gedit /etc/apt/s ...
- logging philosophy 日志哲学
Go kit - Frequently asked questions https://gokit.io/faq/ Logging - Why is package log so different? ...
- Beating JSON performance with Protobuf https://auth0.com/blog/beating-json-performance-with-protobuf/
Beating JSON performance with Protobuf https://auth0.com/blog/beating-json-performance-with-protobuf ...