Was score 2
40
Kit selection
Bob and Alice start painting. There are N numbers of painting kits. The
th
kit has a strength of Az
-10
They need to select these kos Bob got the first chance to selea a kit and he selected a minimum number of kits such that he can make the
painting quickiy. Now, the remaining kits are selected by Alice
Bob can finish his painting before Atce. Fi and only r the total strength of his bits is grester than Alice's
Find the minimum number of kits that must be selected by Bob.
-60
Input format
• The first Ine contains N.
• The second line contains y space separated integers denoring the strengen of kies.
Output format
Print the minimum number of kos tat Bob Must seet
Consuaints
IN < 105
- 500
05 Az = 109
OP
EUS
Answers
import java.util.Scanner;
public class FiftyPrimes
{
// Return true if a number n is prime
public static boolean isPrime(long n)
{
// Check division from 2 to sqrt(n)
for (long i = 2; i <= Math.sqrt(n); i++)
{
if (n % i == 0)
{
return false;
}
}
// If no division is found, number is prime
return true;
}
public static void main(String[] args)
{
// Create Scanner object
Scanner sc = new Scanner(System.in);
// Take user input
System.out.print("Enter the starting point: ");
long start = sc.nextInt();
// Close Scanner object
sc.close();
// If start point is less than 2, make it 2
if (start < 2)
{
start = 2;
}
int numberOfPrimes = 0; // Number of primes printed
long number = start; // Number to be tested for prime
// Iterate until 50 primes are printed
while (numberOfPrimes < 50)
{
if (isPrime(number))
{
System.out.println(number);
numberOfPrimes++;
}
number++;
}
}
}
The Answer to the question is:
def Kit_sol(N,arr):
arr.sort(reverse=True)
Bob = 0
Total_sum = 0
for i in arr:
alice = sum(arr)-i
if Bob > alice:
Total_sum += 1
else:
Bob += i
return Total_sum
N = 5
#int(input())
arr = [5,3,4,1,2]
#list(map(int,input().split()))
out_ = Kit_sol(N, arr)
print(out_)
- Python is an extremely capable general-purpose programming language.
- It is used in web development, data science, and the creation of software prototypes, among other things.
- Python, fortunately, provides a straightforward and easy-to-use syntax for newcomers.
- Python is thus a good language for novices to learn to program with.
SPJ3