Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, m = 0, k = 0;
- cin >> n;
- int a[n+1];
- for(int i = 1; i <= n; i++){
- cin >> a[i];
- }
- int pos[n];
- int sum = 0;
- for(int i = 1; i <= n; i++){
- sum += a[i];
- }
- //cout<<sum<<endl;
- if(a[1] > (sum/2)){
- cout << 1 << "\n" << 1 << endl;
- return 0;
- }
- int j = 1;
- pos[0] = 1;
- m += a[1];
- for(int i = 2; i <= n; i++){
- if(a[1] >= (a[i] * 2)){
- m += a[i];
- //if(m > (sum/2)){
- k++;
- pos[j] = i;
- j++;
- //}
- }
- if(m > (sum/2))
- break;
- }
- //cout << j;
- /*for(int i = 0; i < k; i++){
- cout << pos[i] << " ";
- }
- cout << "\n";*/
- if(k > 0){
- cout << k+1 << endl;
- for(int i = 0; i < k+1; i++){
- cout << pos[i] << " ";
- }
- cout << "\n";
- }
- else{
- cout << 0 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment