当前位置:网站首页>Children play games (greed, prefix and) - Niuke winter vacation training camp
Children play games (greed, prefix and) - Niuke winter vacation training camp
2022-06-26 07:20:00 【Sss_ xxh、】
Original link
subject
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-20xD2fDG-1644926053066)(https://hbn31pkbuk.feishu.cn/space/api/box/stream/download/asynccode/?code=YjcxMjIxNTYwYTg3Y2E4MGNiZWFjMDBhMDFiMmRmZGFfazBraWlyWHd0WklBUjBFTVVWbWJjU21mOUpnTEVIWkZfVG9rZW46Ym94Y243bW9PbEVab1BkN1hrelRSdGxkNGlnXzE2NDQ5MjI5MzE6MTY0NDkyNjUzMV9WNA)]](/img/c2/b8a0c53f34e3d69916814f8c5b4311.jpg)
Ideas
- First, meet the requirements ( Every two noisy children need a quiet child ), Well, at most there can only be n / 2 n/2 n/2 A noisy child
- If the number of quiet children is insufficient n / 2 + n m o d 2 n/2+n\ mod\ 2 n/2+n mod 2 , It outputs
-1. - For the rest, let the quiet children and the noisy children rank in descending order of happiness .
- Then find the prefix sum
- The last comparison is in the least use n / 2 n/2 n/2 What is the greatest happiness of a quiet child .
Code
//
// Created by saber on 2022/2/15.
//
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int suma[N] = {
0};
int sumb[N] = {
0};
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int t; cin >> t;
while (t -- )
{
int a, b, n;
cin >> a >> b >> n;
memset(suma, 0, sizeof suma);
memset(sumb, 0, sizeof sumb);
for (int i = 1; i <= a; i ++ )
{
cin >> suma[i];
}
for (int i = 1; i <= b; i ++ )
{
cin >> sumb[i];
}
sort(suma + 1, suma + 1 + a, cmp);
sort(sumb + 1, sumb + 1 + b, cmp);
for (int i = 1; i <= a; i ++ )
{
suma[i] += suma[i - 1];
}
for (int i = 1; i <= b; i ++ )
{
sumb[i] += sumb[i - 1];
}
int maxn = 0;
int f = n/2 + (n % 2);
if (a < f)
{
cout << -1 << endl;
continue;
}
for (int i = f; i <= min(a, n); i ++ )
{
maxn = max(suma[i] + sumb[n - i], maxn);
}
cout << maxn << endl;
}
return 0;
}
summary
I don't understand , Why such a simple topic , But I couldn't write it out during the game .
边栏推荐
- Parameter index out of range (0 < 1) (1> number of parameters, which is 0
- Professional course - Code question record
- Jemter 压力测试 -基础请求-【教学篇】
- Redis系列——5种常见数据类型day1-3
- The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
- 少年,你可知 Kotlin 协程最初的样子?
- 【推荐一款实体类转换工具 MapStruct,性能强劲,简单易上手 】
- Shell programming - user information management
- [image segmentation] blood vessel extraction from retinal fundus images based on maximum principal curvature with matlab code
- 多传感器融合感知
猜你喜欢

Analyze 5 indicators of NFT project

【推荐一款实体类转换工具 MapStruct,性能强劲,简单易上手 】

执行npm install -g serve时报错权限权限问题解决方案

QTreeWidget And QTableWidget

Liujinhai, chief architect of zhongang Mining: according to the analysis of fluorite supply and demand, it is estimated that the fluorine coating market has great potential

【推荐10个 让你轻松的 IDEA 插件,少些繁琐又重复的代码】

Shell programming - user information management

Young man, do you know the original appearance of kotlin association process?

3,3 '- di (3,4-dicarboxyphenoxy) -4,4' - diphenylethynylbiphenyldianhydride (bpebpda) / porphyrin 2dcofs (H2P COF, ZNP COF and cup COF) supplied by Qiyue
![[image detection] image saliency detection based on ITTI model with matlab code](/img/f3/a8b13431724059f8c8a77961778c67.png)
[image detection] image saliency detection based on ITTI model with matlab code
随机推荐
JS modularization
$a && $b = $c what???
php array_ Merge details
Solution to the permission problem when NPM install -g serve reports an error
Rust中的过程宏
Golang source package collection
QTreeWidget And QTableWidget
ZRaQnHYDAe
Excel中Unicode如何转换为汉字
Meso tetra (4-bromophenyl) porphyrin (tbpp); 5,10,15,20-tetra (4-methoxy-3-sulfonylphenyl) porphyrin [t (4-mop) ps4] supplied by Qiyue
Numpy learning challenge level 5 - create array
两水先木示身为Unity3D职场人的个人觉悟
Procedure macros in rust
Porphyrin based polyimide ppbpis (ppbpi-pa, ppbpi-pepa and ppbpi-pena); Crosslinked porphyrin based polyimide (ppbpi-pa-cr, ppbpi-pepa-cr, ppbpi-pena-cr) reagent
【推荐一款实体类转换工具 MapStruct,性能强劲,简单易上手 】
Installation homebrew error summary
The difference between insert ignore and insert into
Zraqnhydae
The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
Market survey of China's coal to liquid industry and analysis report on investment competitiveness during the "14th five year plan" 2022-2027