Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
int seats = 0;
for(auto i = 0; i < n; i++){
cin>>arr[i];
seats += arr[i];
}
int party = arr[0];
int coalition = party, k = 0, i = 0;
int arrn[n];
int cvheck = 0;
while(i < n-1){
i++;
if(arr[i] <= party/2){
coalition += arr[i];
arrn[k] = i;
k++;
}
}
if(coalition < = seats/2){
cout<<0<<endl;
return 0;
}
cout<<k+1<<endl;
cout<<1<<" ";
for(auto i = 0; i < k; i++>{
cout<<arrn[i]+1
<<" ";
}
}
Copy The Code &
Try With Live Editor
Input
3
100 50 50
100 50 50
Output
2
1 2
1 2
Demonstration
Codeforcess solution 1178-A A. Prime Minister C++, Java, Js and Python ,1178-A Codeforcess solution