题目链接:https://codeforces.com/contest/1369/problem/C

题意

将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^{k}w_i = n$),每个人的快乐值为分到数的最小值和最大值之和,计算所有人快乐值之和的最大值。

题解

将 $n$ 个数从小到大排序后从两边加起,利用较大的 $w_i$ 跳过尽可能多的较小值。

代码

#include <bits/stdc++.h>
using ll = long long;
using namespace std; void solve() {
int n, k; cin >> n >> k;
int a[n] = {};
for (int i = 0; i < n; i++)
cin >> a[i];
int w[k] = {};
for (int i = 0; i < k; i++)
cin >> w[i];
sort(a, a + n);
sort(w, w + k, greater<int>());
ll ans = 0;
int l = 0, r = n - k;
for (int i = 0; i < k; i++) {
if (w[i] == 1) {
ans += a[r] + a[r];
++r;
} else {
ans += a[l++] + a[r++];
l += w[i] - 2; //跳过的较小值
}
}
cout << ans << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #652 (Div. 2) C. RationalLee(贪心)的更多相关文章

  1. Codeforces Round #652 (Div. 2) C. RationalLee 贪心

    题意: t组输入,你有n个数,还有k个朋友,每一个朋友需要wi个数.意思就是你要给第i个朋友分配wi个数,输入保证w1+w2+...+wk=n 一个朋友的兴奋值是你分配给他的数中最大值加上最小值的和( ...

  2. Codeforces Round #652 (Div. 2) E. DeadLee 贪心

    题意: 派会上有n种食物,每种食物有wi份.有m个朋友,每一个朋友有两种他喜欢吃的食物xi,yi.你需要判断他的朋友是否都能吃到食物.如果都能吃到食物,那么要输出朋友来的顺序,不能的话输出" ...

  3. Codeforces Round #652 (Div. 2) E. DeadLee(贪心)

    题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友 ...

  4. 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 ...

  5. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  6. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  7. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  8. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  9. 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 ...

随机推荐

  1. FastApi学习(二)

    前言 继续学习 此为第二篇, 还差些知识点就可以结束, 更多的比如用户的身份校验/ swagger 文档修改等以后会单独写 正文 使用枚举来限定参数 可以使用枚举的方式来限定参数为某几个值之内才通过 ...

  2. TypeScript接口与类的使用

    一.TypeScript接口 Interfaces 可以约定一个对象的结构 一个对象去实现一个接口 就必须拥有这个接口中所有的成员用interface定义接口, 并且定义接口中成员的类型 编译之后会发 ...

  3. (十)Python装饰器

    装饰器:本质就是函数,功能是为其他函数添加附加功能. 两个原则: 1.不修改被修饰函数的源代码 2.不修改被修饰函数的调用方式 一个栗子 def test(): res = 0 for i in ra ...

  4. 通过show profile分析sql语句

    set profling=1; select count(*) from xuehao; show profiles; show profile for query 1; mysql> set ...

  5. 如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

    如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

  6. 【Linux】快速创建文件的命令方法

    [root@centos7 dir1]# ll total 0 -rw-r--r-- 1 root root 0 Aug 15 02:39 file1 -rw-r--r-- 1 root root 0 ...

  7. Linux下Too many open files问题排查与解决

    作者: Grey 原文地址: Github 语雀 博客园 Too many open files是Linux系统中常见的错误,从字面意思上看就是说程序打开的文件数过多,不过这里的files不单是文件的 ...

  8. 误删除SAP ECC中的profile文件

    环境:ECC6.0 EHP4  FOR ORACLE ON WINDWS X64下 今天在RZ10配置系统参数文件的时候,不小心错删除了instance profile文件,这下惨了,这是操作系统层级 ...

  9. SAP内表类型及其数据读取效率评估

    内表大概分3种: 1.标准表standard tables:如果不指定BINARY SEARCH附加选项,则默认为线性查找(linear search),既一条一条的查找. 2.排序表(sorted ...

  10. Building a high performance JSON parser

    Building a high performance JSON parser https://dave.cheney.net/high-performance-json.html