For each test case t, I need to input n, the number of elements in an array, and input those elements. Then I have to subtract the smallest element in the array from the sum of all the other elements. Here is my code, but I keep getting TLE:
#include <bits/stdc++.h>
int main(void) {
int t;
std::cin >> t;
while (t --) {
int n, sum = 0, a, k = 100000;
std::cin >> n;
while (n --) {
std::cin >> a;
if (a < k) {
k = a;
} else {
sum += a;
}
n --;
}
std::cout << abs(sum - k) << "\n";
}
}
Sample Input:
3
5
20 16 8 2 13
6
16 9 12 20 15 14
4
2 2 2 2
Sample Output:
55
68
4