Problem:
Score : 100 points

Problem Statement

There are a total of A + B cats and dogs.
Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.

Determine if it is possible that there are exactly X cats among these A + B animals.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

1 \leq X \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B X

Output

If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

Sample Input 1

3 5 4

Sample Output 1

YES

If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.

Sample Input 2

2 2 6

Sample Output 2

NO

Even if all of the B = 2 animals are cats, there are less than X = 6 cats in total.

Sample Input 3

5 3 2

Sample Output 3

NO

Even if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  int a[10000];
  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  int max = 0;
  int max_id = 0;
  for(int i = 0;i < n;i++){
    if(max < a[i]){
      max = a[i];
      max_id = i;
    }
  }

  int id_1,id_2;
  if(max % 2 != 0){
    id_1 = max / 2;
    id_2 = max / 2 + 1;
  }else{
    id_1 = id_2 = max/2;
  }

  int r = -1;
  while(1){
    for(int i = 0;i < n;i++){
      if(i != max_id){
        if(a[i] == id_1 || a[i] == id_2){
          r = i;
          break;
        }
      }
    }
    if(r != -1){
      break;
    }else{
      id_1++;
      id_2--;
    }
  }

  cout << max << " " << a[r] << endl;
  return(0);
}