当前位置:网站首页>Question g: candy
Question g: candy
2022-06-11 02:00:00 【Jihai】
problem G: candy
The time limit : 1.000 Sec Memory limit : 128 MB
Title Description
Yes n Two children , Yes m Bag of candy , The first i The number of sweets in the bag is a[i]. It is known that n<=m<2n. Each child should have at least one bag of candy , You can only have two bags of candy at most . The goal of the assignment is to put this m All the bags of candy are divided , And make sure that each child gets the same amount of candy . If it can be done, output ”possible”, If not, output ”impossible”. Be careful : Can't open a bag of candy , It must be distributed in whole bags .
Input
first line , A positive integer R, Express R Group test data .1<=R<=10.
The format of each set of test data is :
first line , Two integers n and m.1<=n<=50.n<=m<2n.
The second line ,m It's an integer , The first i An integer is a[i].1<=a[i]<=1000.
Output
common R That's ok , One string per line ,”possible” perhaps ”impossible”, Double quotation marks do not need to be output .
The sample input
4 1 1 47 3 5 10 8 10 1 1 3 5 3 9 10 7 1 6 11 1 1 1 2 1 1 1 1 1 1 1
Sample output
possible impossible possible possible
Code :
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int w;
cin >> w;
while (w--) {
int peo, n, peo_n[55]{}, candy[110], i, t;
cin >> peo >> n;
if (peo > n || n > 2 * peo)
{
cout << "impossible";
continue;
}
for (i = 0; i < n; i++)
{
cin >> candy[i];
}
sort(candy, candy + n);
for (i = n - 1; i >= n - peo; i--)
{
peo_n[n - i - 1] = peo_n[n - i - 1] + candy[i];
}
if (n > peo)
{
for (i = n - peo; i > 0; i--)
{
peo_n[i] += candy[i - 1];
}
}
int temp = peo_n[0];
bool qq = 0;
for (i = 1; i < peo; i++)
{
if (temp != peo_n[i])
{
qq = 1;
}
}
if (qq == 1)
cout << "impossible";
else
cout << "possible";
cout << endl;
}
return 0;
}边栏推荐
- 1.4px4 program download
- EXJ形儿多眼前因断会满意接MBtXE
- 【HaaS Hands-On】全新视频节目上线 创意案例我们一起上手做 第一期E01: 物联网工程师 和你一起上手做遥控机械臂
- 2021-02-03美赛前MATLAB的学习笔记(灰色预测、线性规划)
- Leetcode 1248 count number of nice subarrays
- CLIP论文详解
- [leetcode] flat multi-level bidirectional linked list
- 关于CS-3120舵机使用过程中感觉反应慢的问题
- In May, the main growth ranking list (platform of station B) of the single flying melon data up was released
- Matlab array other common operation notes
猜你喜欢
随机推荐
[leetcode] notes on recursive time value transfer and reference transfer
[music] playing blue and white porcelain based on MATLAB [including Matlab source code 1873]
[matlab] image enhancement (power transformation, histogram specification processing method, smoothing and sharpening filtering)
Method of using dism command to backup driver in win11 system
2021-3-1MATLAB写cnn的mnist数据库训练
2021-02-27image processing of MATLAB
(已解决)Latex--取消正文中参考文献引用的上标显示(gbt7714-2015会导致默认上角标引用)(上角标&平齐标混合使用教程)
How to change the theme of win11 touch keyboard? Win11 method of changing touch keyboard theme
并发编程基础底层原理学习(四)
【圖像處理】基於matlab GUI多功能圖像處理系統【含Matlab源碼 1876期】
On permutation and Combination in Probabilistic Statistics
【Qt】error: QApplication: No such file or directory 解决方案
[leetcode] reverse linked list
Task03: stack
Sparrowrecsys recurrence record
flutter 状态管理
2021-7-18 ROS notes XML language related
Task06: bit operation
中國各省份省會的坐標
C语言 深度探究具有不定参数的函数








