fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10.  
  11. int n;
  12. cin>>n;
  13.  
  14. vector<int> dist(n-1);
  15.  
  16. for(int i=0; i<n-1; i++)
  17. cin>>dist[i];
  18.  
  19. vector<int> pos(n);
  20. pos[0] = 0;
  21.  
  22. for(int i=1; i<n; i++)
  23. pos[i] = pos[i-1] + dist[i-1];
  24.  
  25. int total_length = pos[n-1];
  26. int min_max = total_length;
  27.  
  28. vector<int> candidates;
  29.  
  30. for(int i=0; i<n; i++)
  31. {
  32. long long max_dist = max(pos[i], total_length-pos[i]);
  33.  
  34. if(max_dist < min_max)
  35. {
  36. min_max = max_dist;
  37. candidates.clear();
  38. candidates.push_back(i+1);
  39. }
  40.  
  41. else if(max_dist == min_max)
  42. {
  43. candidates.push_back(i+1);
  44. }
  45. }
  46.  
  47. for(int x : candidates)
  48. cout<<x<<'\n';
  49.  
  50. return 0;
  51. }
  52.  
  53.  
  54.  
  55.  
Success #stdin #stdout 0s 5320KB
stdin
7
2 3 2 2 4 1
stdout
4