-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwins.cpp
More file actions
51 lines (49 loc) · 1005 Bytes
/
Twins.cpp
File metadata and controls
51 lines (49 loc) · 1005 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
#include<iostream>
using namespace std;
int main()
{
int n; // n => number of coins
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
// for(int i=0;i<n;i++){
// cout<<value[i]<<" ";
// }
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1;j++){
if(arr[j]>arr[j+1]){
int temp;
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
// for(int i=0;i<n;i++){
// cout<<arr[i]<<" ";
// }
int l = n-1;
int sum=0;
for(int i=0;i<n;i++){
sum += arr[i];
}
// sum = 15
if(arr[l]>sum-arr[l]){
cout<<"1";
}
else {
while(l>=0){
arr[l-1]=arr[l]+arr[l-1];
if(arr[l-1]>sum-arr[l-1]){
cout<<n-l+1;
break;
}
else if(arr[l-1]<sum-arr[l-1]){
l--;
}
}
}
return 0;
}