Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int t = sc.nextInt();
- while(t-->0){
- int numBooks = sc.nextInt();
- long[] books = new long[numBooks];
- for (int i = 0; i < numBooks; i++) {
- books[i] = sc.nextLong();
- }
- Arrays.sort(books);
- long sum = 0;
- for (int j = 0; j < books.length - 1; j++) {
- sum += books[j];
- }
- if (sum < books[numBooks - 1]) {
- System.out.println(books[numBooks - 1] * 2);
- } else {
- System.out.println(sum + books[numBooks - 1]);
- }
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment