alvy10

Untitled

Jul 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, m = 0, k = 0;
  8. cin >> n;
  9.  
  10. int a[n+1];
  11.  
  12. for(int i = 1; i <= n; i++){
  13. cin >> a[i];
  14. }
  15.  
  16. int pos[n];
  17. int sum = 0;
  18.  
  19. for(int i = 1; i <= n; i++){
  20. sum += a[i];
  21. }
  22.  
  23. //cout<<sum<<endl;
  24.  
  25. if(a[1] > (sum/2)){
  26. cout << 1 << "\n" << 1 << endl;
  27. return 0;
  28. }
  29.  
  30. int j = 1;
  31. pos[0] = 1;
  32. m += a[1];
  33.  
  34. for(int i = 2; i <= n; i++){
  35. if(a[1] >= (a[i] * 2)){
  36. m += a[i];
  37. //if(m > (sum/2)){
  38. k++;
  39. pos[j] = i;
  40. j++;
  41. //}
  42. }
  43.  
  44. if(m > (sum/2))
  45. break;
  46. }
  47. //cout << j;
  48.  
  49. /*for(int i = 0; i < k; i++){
  50. cout << pos[i] << " ";
  51. }
  52.  
  53. cout << "\n";*/
  54.  
  55. if(k > 0){
  56. cout << k+1 << endl;
  57. for(int i = 0; i < k+1; i++){
  58. cout << pos[i] << " ";
  59. }
  60.  
  61. cout << "\n";
  62. }
  63. else{
  64. cout << 0 << endl;
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment