Only divisible Given an array A of N integers, and an integer x. For each element in A you can do the following operatio

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Only divisible Given an array A of N integers, and an integer x. For each element in A you can do the following operatio

Post by answerhappygod »

Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 1
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 1 (124.5 KiB) Viewed 51 times
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 2
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 2 (165.59 KiB) Viewed 51 times
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 3
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 3 (161.8 KiB) Viewed 51 times
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 4
Only Divisible Given An Array A Of N Integers And An Integer X For Each Element In A You Can Do The Following Operatio 4 (136.46 KiB) Viewed 51 times
help asap thank you.
Only divisible Given an array A of N integers, and an integer x. For each element in A you can do the following operation at most once : add +1 or -1 to A. (1<i< N). Let S be the summation of elements of some subsequence in A after performing some operations. Find the maximum integer S such that S is divisible by x, Le (S % x = 0). Example Consider N = 3, X = 2, Al] =[1, 2, 3]. • Increase A[1] by 1. we get- A=[2, 2, 3]. • increase A[2] by 1. we get- A=[2, 3, 3]. The Sum of the above array is 8. and it is also divisible by X-2. so, this is the maximum possible value of S. Function description Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the maximum possible S.:
comprene une surve toncuon provided in the comfor. This following 3 parameters and returns the maximum possible S.: • N: Represents the size of the Array. • X: Represents the number. • A: Represents the array N of size N Input format Note: This is the input format that you must use to provide custom input (available above the Compile and Test button). . In the first line, you will be given two integers N and X. • for each of the following N lines, the ith line contains one integer A. Output format • one integer S. Constraints 1<N<100 1≤ A ≤ 109 1<7<105 Code snippets (also called starter code/boilerplate code)
1≤A ≤ 109 1≤#≤ 105 Code snippets (also called starter code/boilerplate code) This question has code snippets for C, CPP, Java, and Python. Sample input D 54 4 8 6 2 1 Sample output 24 Explanation the maximum sum that could be achieved by adding 1 to A[1], A[2], A[3] and A[4], and the answer is the sum of these 4 values. L
espace std; long long Solve (int n, int x, vector<int> a) { } int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N int X; cin >> X; vector<int> A(N); for(int i_A = 0; i_A < N; i_A++) { cin >> A[i_A]; } long long out_;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply