PROBLEM A:
Create a variable max, a variable sum and a variable pos. Set max=0, sum=0, pos=0. Iterate through the array and add arr[I] to sum. If sum>max then save i in the variable pos=i, and set max to the current sum. After you are done iterating print pos.
PROBLEM B.
The following greedy solutions always works: Sort the array arr, and then iterate until you find the minimum even number. If at the end of the loop it doesn’t exist then we have no answer and the solution is −1. Because we can not create an even number without any even digits. If there is an even element, save it’s index to a variable.Then print the array decreasing order (from n to 1)without the minimum even digit(the element at the saved index). After printing the array, print the minimum even digit so the number will be even.
Problem C:
Problem D:
There are 2 cases:
If k is even Bob makes the last move and he can always insert a prime number such that the gcd of the array is 1.
If k is odd then Alice makes the last move. Alice wins if we can remove an element from the starting array such that the gcd of arr is bigger than 1. To find this out we can use the fundamental theory of arithmetic which states that any integer can be expressed as a product of prime numbers.For each element in the array we find what primes divide it by iterating through all the primes under 100(since it is given that ai≤100). If any prime divides more than n−1 elements Alice wins since if Bob introduces a number Alice can delete that number in the next move. If no prime divides more than n−1 elements then bob wins.
Another solution for when k is odd is with prefix and suffix gcd. Iterrate over all ai from 1 to n and set prefixgcd[i]=gcd(prefixgcd[i−1],prefixgcd[i]). Then do the same for suffixgcd, but in reverse order: from n to 1 and set every element suffixgcd[i]=gcd(suffixgcd[i+1],suffixgcd[i]). Be careful at prefixgcd1 and suffixgcdn, You should just attribute them the value of the element at the index. After that we just iterate over all the array and check if gcd(prefixgcd[i−1],suffixgcd[i+1])>1 ( again, be careful at a1 and an). If this is true for at least one element then the answer is "YES". But if we can not find such i then the answer is "NO".
Problem E: