目录
A-Nearest Interesting Number
题意:
思路:
代码:
B-Equalize Prices
题意:
思路:
代码:
C-Computer Game
题意:
思路:
代码:
D-Candy Box (easy version)
题意:
思路:
代码:
Polycarp knows that if the sum of the digits of a number is divisible by 33, then the number itself is divisible by 33. He assumes that the numbers, the sum of the digits of which is divisible by 44, are also somewhat interesting. Thus, he considers a positive integer nn interesting if its sum of digits is divisible by 44.
Help Polycarp find the nearest larger or equal interesting number for the given number aa. That is, find the interesting number nn such that n \ge an≥a and nn is minimal.
Input
The only line in the input contains an integer aa (1 \le a \le 10001≤a≤1000).
Output
Print the nearest greater or equal interesting number for the given number aa. In other words, print the interesting number nn such that n \ge an≥a and nn is minimal.
Examples
Input
432
Output
435
Input
99
Output
103
Input
237
Output
237
Input
42
Output
44
定义有趣的数:如果一个正整数的每位数相加得到的结果能被四整除,那么这个正整数就是有趣的数。
输入一个数,输出大于或等于这个数的最小的有趣数。
直接判断即可
#include
using namespace std;
int sum(int a)
{
int ans=0;
while(a)
{
ans+=a%10;
a/=10;
}
return ans;
}
int main()
{
int a;
cin>>a;
while(sum(a)%4)
{
a++;
}
cout<
There are nn products in the shop. The price of the ii-th product is a_iai. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.
In fact, the owner of the shop can change the price of some product ii in such a way that the difference between the old price of this product a_iai and the new price b_ibi is at most kk. In other words, the condition |a_i - b_i| \le k∣ai−bi∣≤k should be satisfied (|x|∣x∣ is the absolute value of xx).
He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price b_ibi of each product ii should be positive (i.e. b_i > 0bi>0 should be satisfied for all ii from 11 to nn).
Your task is to find out the maximum possible equal price BB of all productts with the restriction that for all products the condiion |a_i - B| \le k∣ai−B∣≤k should be satisfied (where a_iai is the old price of the product and BB is the same new price of all products) or report that it is impossible to find such price BB.
Note that the chosen price BB should be integer.
You should answer qq independent queries.
Input
The first line of the input contains one integer qq (1 \le q \le 1001≤q≤100) — the number of queries. Each query is presented by two lines.
The first line of the query contains two integers nn and kk (1 \le n \le 100, 1 \le k \le 10^81≤n≤100,1≤k≤108) — the number of products and the value kk. The second line of the query contains nn integers a_1, a_2, \dots, a_na1,a2,…,an (1 \le a_i \le 10^81≤ai≤108), where a_iai is the price of the ii-th product.
Output
Print qq integers, where the ii-th integer is the answer BB on the ii-th query.
If it is impossible to equalize prices of all given products with restriction that for all products the condition |a_i - B| \le k∣ai−B∣≤k should be satisfied (where a_iai is the old price of the product and BB is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
Example
Input
4 5 1 1 1 2 3 1 4 2 6 4 8 5 2 2 1 6 3 5 5 2 5
Output
2 6 -1 7
Note
In the first example query you can choose the price B=2B=2. It is easy to see that the difference between each old price and each new price B=2B=2 is no more than 11.
In the second example query you can choose the price B=6B=6 and then all the differences between old and new price B=6B=6 will be no more than 22.
In the third example query you cannot choose any suitable price BB. For any value BB at least one condition out of two will be violated: |1-B| \le 2∣1−B∣≤2, |6-B| \le 2∣6−B∣≤2.
In the fourth example query all values BB between 11 and 77 are valid. But the maximum is 77, so it's the answer.
给你n个老价格,现在需要定一个新价格使得所有老价格与新价格差的绝对值小于等于k,问新价格的最大值,没有满足条件的输出-1。
老价格的最大、最小值之差如果大于2*k肯定输出-1,否则输出最小值+k。
#include
#include
using namespace std;
int main()
{
int q;
cin>>q;
while(q--)
{
int a[200];
int n,k;
cin>>n>>k;
for(int i=0;i>a[i];
}
sort(a,a+n);
if(a[n-1]-a[0]>2*k)
cout<<-1<
Vova is playing a computer game. There are in total nn turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is kk.
During each turn Vova can choose what to do:
Regardless of Vova's turns the charge of the laptop battery is always decreases.
Vova wants to complete the game (Vova can complete the game if after each of nn turns the charge of the laptop battery is strictly greater than 00). Vova has to play exactly nn turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.
Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.
You have to answer qq independent queries.
Input
The first line of the input contains one integer qq (1 \le q \le 10^51≤q≤105) — the number of queries. Each query is presented by a single line.