E New Max
n=400暴力求解 k可以为0 0次操作旧的最大值等于新的最大值
或者二分lower_bound
Kamal 'D has an array of size N.
He can do at most K operations on it, in each operation he can choose any element in the array and change its value to any other value X, (1≤x≤400).
Kamal 'D wants to know if he can make the maximum element in the new array equal to M.
输入
The first line of input will contain 3 integers N, M and K (1≤N≤400) (0≤K≤400) (1≤M≤400) which are the size of the array, the new maximum value and the number of operations.
The second line will contain n integers, the ith one is ai which is the ith element in array a, (1≤ai≤400)
输出
For each test case, print “YES” if Kamal 'D can make the maximum element equals to M, print “NO” otherwise .
Input
6 4 3
1 5 3 4 2 6
Output
YES
Input
6 4 2
5 5 5 5 1 2
Output
NO
1.暴力
#include
#include
#include
#include
#include
#include
#include
#include
#include
2.二分
#include
#include
#include
#include
#include
#include
#include
#include
#include
I
同余
回文串对应位置差值取gcd即可
找到任意一个数和他对应数字的因子的差,模差值同余
然后枚举它的因子作为mod能否形成回文串/直接对于所有数字和其对应的数字的差,取gcd即可
Abu Tahun loves palindromes.
An array is palindrome if it reads the same backwards and forwards, for example arrays {1}, {1,1,1}, {1,2,1} , {1,3,2,3,1} are palindrome, but arrays {11,3,5,11}, {1,12} are not.
Abu Tahun has an array of n integers A. He wants his array to be palindrome. He can choose an integer m, then change the value of all Ai (1≤i≤n) to (Ai mod m).
what is the maximum value of m he can choose, such that the array becomes palindrome?
input
The first line of input contains a single integer n (1≤n≤105)
The second line contains integers A1,A2,…,An (1≤Ai≤109)
output
Print the maximum value of m Abu Tahun can choose, if m is arbitrarily large print -1.
input
4
1 1 1 1
Output
-1
4
1 2 3 4
1
3
8 12 16
8
#include
#include
#include
#include
#include
#include
#include
#include
#include
J Negative effect 前缀和+特判
题意枚举替换正整数数组每一个位置为负数m 替换后求所有子数组和最大值
注意特判 n=1情况 前缀后缀为0 ans=max(0,0+m负数)=0 而一个数替换后 和应为m 前缀和爆int 用ll
Abu tahun has an array a of n positive integers, and a negative integer m.
Abu Tahun defines the beauty of the array as the maximum summation of a sub-array in that array.
A sub-array of an array is a sequence of consecutive integers in the array.
For example :
The beauty of array {1,−5,7} equals to 7.
And the beauty of array {6,−5,7} equals to 8.
in the second example we have the sub-arrays :
{6} sum = 6, {−5} sum = -5, {7} sum = 7, {6,−5} sum = 1, {−5,7} sum = 2, {6,−5,7} sum = 8.
You should tell Abu Tahun, for every index if he replaced the number in that index with m, what is the beauty of the resulting array.
Input
First line of input contains two integers n and m (1≤n≤105) (−109≤m<0)
The second line will contain n integers, the ith one is ai, which is the ith element in the array, (1≤ai≤109).
Output
You should print n integers, the ith one should be the beauty of the given array after replacing the ith integer with m.
Input
4 -3
1 2 3 4
Output
9 7 4 6
#include
#include
#include
#include
#include
#include
#include
#include
#include
B STL map 求余数组num存不下
只有当剩下1个 或 每一对差值求余m余数为0才结束 即剩下的同余
As Ayoub was going home from Mahmoud’s house, he remembered that he forgot his hard disk, which contains the solutions to n problems from the JU Flash contest. The ith problem has size ai.
While panicking, he remembered that he installed a software that prevented the user from copying any files and only allowed the files to be cut from the hard disk in any order the user wants.
As a security measure, the software will stop the transfer if the number of remaining files is 1, or the absolute difference between the sizes ofevery pair of problems left on the hard disk is divisible by m.
Ayoub knows the permutation b, which represents the order of the problems Mahmoud will attempt to cut from the hard disk.
Since Ayoub is a bad programmer, he asks for your help to tell him how many problems Mahmoud will steal until the transfer stops.
Input
The first line contains two integer n and m (1≤n≤105) (1≤m≤109)
The second line contains integers a1,a2,…,an (1≤ai≤109)
The third line contains a permutation b , b1,b2,…,bn (1≤bi≤105)
Output
print exactly one integer − the number of codes Mahmoud can steal
Input
3 2
2 1 4
2 1 3
Output
1
Input
3 2
2 1 4
3 2 1
Output
2
Input
5 2
7 9 5 33 77
5 3 4 2 1
Output
0
#in]clude
#include
#include
#include
#include
#include
#include
#include
#include