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 >= 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 << biggest + 1;
  21. }
  22.  
  23. } else if (smallest == 0) {
  24. cout << n;
  25. } else {
  26. cout << 1;
  27. }
  28. }
Success #stdin #stdout 0s 5308KB
stdin
5
1 2 3 4
stdout
2