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. cout << smallest + 1;
  18.  
  19. } else if (smallest == 0) {
  20. cout << n;
  21. } else {
  22. cout << 1;
  23. }
  24. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
2 5 1 4
stdout
5