forked from omonimus1/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic-element.cpp
More file actions
51 lines (41 loc) · 811 Bytes
/
magic-element.cpp
File metadata and controls
51 lines (41 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// https://www.codechef.com/problems/ZOZ
#include <iostream>
using namespace std;
int solve_test()
{
/*
4 4
2 1 6 7
4 2
2 1 5 4
*/
int n, k;
cin >> n >> k;
int arr[n]; // = {2,1,6,7};
for (int i = 0; i < n; i++) cin >> arr[i];
int magic = 0;
int sum;
int incremented_value;
for (int i = 0; i < n; i++)
{
incremented_value = arr[i] + k;
sum = 0;
for (int j = 0; j < n; j++)
{
if (i == j)
continue;
sum += arr[j];
}
if (incremented_value > sum)
magic++;
}
return magic;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
cout << solve_test() << endl;
return 0;
}