Recently a new building with a new layout was constructed in Monocarp‘s hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It‘s also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.
Monocarp went around the building and counted nn windows. Now he is wondering, how many apartments of each type the building may have.
Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has nn windows. If there are multiple answers, you can print any of them.
Here are some examples:
if Monocarp has counted 3030 windows, there could have been 22 three-room apartments, 22 five-room apartments and 22 seven-room apartments, since 2?3+2?5+2?7=302?3+2?5+2?7=30;
if Monocarp has counted 6767 windows, there could have been 77 three-room apartments, 55 five-room apartments and 33 seven-room apartments, since 7?3+5?5+3?7=677?3+5?5+3?7=67;
if Monocarp has counted 44 windows, he should have mistaken since no building with the aforementioned layout can have 44 windows.
Input
Th first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The only line of each test case contains one integer nn (1≤n≤10001≤n≤1000) — the number of windows in the building.
Output
For each test case, if a building with the new layout and the given number of windows just can‘t exist, print ?1?1.
Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.
Example
input
Copy
4
30
67
4
14
output
Copy
2 2 2
7 5 3
-1
0 0 2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
int T; cin >> T;
while (T -- ) {
int n; cin >> n;
int f = 0;
for (int i = 0; i * 7 <= n; i ++ ) {
for (int j = 0; j * 5 <= n; j ++ ) {
int k = n - i * 7 - j * 5;
if (k % 3 == 0 && k >= 0) {
f = 1;
cout<<k/3<<‘ ‘<<j <<‘ ‘<< i<< endl;
break;
}
}
if (f) break;
}
if (!f) puts("-1");
}
return 0;
}
B. Barrels
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You have nn barrels lined up in a row, numbered from left to right from one. Initially, the ii-th barrel contains aiai liters of water.
You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels xx and yy (the xx-th barrel shouldn‘t be empty) and pour any possible amount of water from barrel xx to barrel yy (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them.
Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most kk times.
Some examples:
if you have four barrels, each containing 55 liters of water, and k=1k=1, you may pour 55 liters from the second barrel into the fourth, so the amounts of water in the barrels are [5,0,5,10][5,0,5,10], and the difference between the maximum and the minimum is 1010;
if all barrels are empty, you can‘t make any operation, so the difference between the maximum and the minimum amount is still 00.
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The first line of each test case contains two integers nn and kk (1≤k<n≤2?1051≤k<n≤2?105) — the number of barrels and the number of pourings you can make.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109), where aiai is the initial amount of water the ii-th barrel has.
It‘s guaranteed that the total sum of nn over test cases doesn‘t exceed 2?1052?105.
Output
For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most kk times.
Example
input
Copy
2
4 1
5 5 5 5
3 2
0 0 0
output
Copy
10
0
//简单的模拟一下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2000010;
int main(){
int T; scanf("%d", &T);
while (T -- ) {
int n, k; scanf("%d%d", &n, &k);
int a[N];
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
sort(a, a + n);
int cnt = 0;
long long sum = a[n - 1];
for (int i = n - 2; i >= 0; i -- ) {
cnt ++;
sum += a[i];
if (cnt >= k) {
printf("%lld\n", sum);
break;
}
}
}
return 0;
}