-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path160A-Twins.cpp
More file actions
59 lines (27 loc) · 915 Bytes
/
160A-Twins.cpp
File metadata and controls
59 lines (27 loc) · 915 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
52
53
54
55
56
57
58
59
#include <bits/stdc++.h> // this includes everything
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); // for efficiency
int n{0}; // number of coin
cin >> n;
int A[n]; // this array stores the value of n number of coin
int sum{0};
int sum2{0};
int count{0};
for(int i = 0; i< n; i++) // from first to last
{
cin >> A[i];
sum += A[i] ;// sum of all the coin // a += b; is equivalent to a = a + b
}
sum = sum/2; // half of the given money
sort(A, A+n);// sorts the number form small to big // from first(A) to last(A+n)
for(int j = n -1; j>=0 ;j--) // from last to fast // input:5 , output: 4 3 2 1 0
{
sum2+= A[j];
count++;
if(sum< sum2){ break;}
}
cout << count << "\n";
return 0;
}