Sasha decided to give his girlfriend an array a1,a2,…,an�1,�2,…,��. He found out that his girlfriend evaluates the beauty of the array as the sum of the values (ai−ai−1)(��−��−1) for all integers i� from 22 to n�.
Help Sasha and tell him the maximum beauty of the array a� that he can obtain, if he can rearrange its elements in any way.
Each test consists of multiple test cases. The first line contains a single integer t� (1≤t≤5001≤�≤500) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n� (2≤n≤1002≤�≤100) — the length of the array a�.
The second line of each test case contains n� integers a1,a2,…,an�1,�2,…,�� (1≤ai≤1091≤��≤109) — the elements of the array a�.
For each test case, output a single integer — the maximum beauty of the array a� that can be obtained.
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,a[105],min=1e9,max=-1;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
printf("%d\n",max-min);
}
return 0;
}
Even in kindergarten, Sasha liked a girl. Therefore, he wanted to give her a drawing and attract her attention.
As a drawing, he decided to draw a square grid of size n×n�×�, in which some cells are colored. But coloring the cells is difficult, so he wants to color as few cells as possible. But at the same time, he wants at least k� diagonals to have at least one colored cell. Note that the square grid of size n×n�×� has a total of 4n−24�−2 diagonals.
Help little Sasha to make the girl fall in love with him and tell him the minimum number of cells he needs to color.
Each test consists of multiple test cases. The first line contains a single integer t� (1≤t≤10001≤�≤1000) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers n� and k� (2≤n≤1082≤�≤108, 1≤k≤4n−21≤�≤4�−2) — the size of the square grid and the minimum number of diagonals in which there should be at least one colored cell.
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d %d",&n,&k);
if(k==4*n-2)
printf("%d\n",2*n);
else
printf("%d\n",(k+1)/2);
}
return 0;
}
Sasha decided to give his girlfriend the best handbag, but unfortunately for Sasha, it is very expensive. Therefore, Sasha wants to earn it. After looking at earning tips on the internet, he decided to go to the casino.
Sasha knows that the casino operates under the following rules. If Sasha places a bet of y� coins (where y� is a positive integer), then in case of winning, he will receive y⋅k�⋅� coins (i.e., his number of coins will increase by y⋅(k−1)�⋅(�−1)). And in case of losing, he will lose the entire bet amount (i.e., his number of coins will decrease by y�).
Note that the bet amount must always be a positive (>0>0) integer and cannot exceed Sasha's current number of coins.
Sasha also knows that there is a promotion at the casino: he cannot lose more than x� times in a row.
Initially, Sasha has a� coins. He wonders whether he can place bets such that he is guaranteed to win any number of coins. In other words, is it true that for any integer n�, Sasha can make bets so that for any outcome that does not contradict the rules described above, at some moment of time he will have at least n� coins.
#include<stdio.h>
int main()
{
long long t;
scanf("%lld",&t);
while(t--)
{
long long k,x,a,s=0,t=1;
scanf("%lld %lld %lld",&k,&x,&a);
for(int i=0;i<=x;i++)
{
s+=t;
t=s/(k-1)+1;
}
if(s<=a)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}