fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int smallest = 0, biggest = n + 1, x;
  8. for (int i = 1; i < n; ++i) {
  9. cin >> x;
  10. if (biggest - x <= x - smallest) {
  11. biggest = x;
  12. } else {
  13. smallest = x;
  14. }
  15. }
  16. if (biggest - smallest >= 2 || smallest - biggest >= 2) {
  17. if (biggest > smallest) {
  18. cout << smallest + 1;
  19. } else {
  20. cout << smallest - 1;
  21. }
  22. } else if (smallest == 0) {
  23. cout << n;
  24. } else {
  25. cout << 1;
  26. }
  27. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
2 5 1 4
stdout
2