UVa Problem no. 10038.(Can’t get correct output for some cases)

I am currently solving the UVa Problem no. 10038. So, to debug my code I went to uDebug. And found that my code was almost complete but with some exceptions.

I want the following code to reviewed. Any suggestions for editting can be helpful.

I have tried using while loop(at the near end of code) instead of the if statement but that freezes the input.

/*#include <iostream>, <vector>, <algorithm>, <functional>*/  int main(){ /*Declaring everything required*/     int n, num, diff;     bool is_jolly;     vector<int> numbers, differences;      while(cin >> n){         /*Deleting all elements before working with them*/         numbers.clear();         differences.clear();  /*A sequence of single number is always JOLLY*/              /*Taking in all the numbers*/             for(int i = 0; i < n; i++){                 cin >> num;                 numbers.push_back(num);             }              /*Calculating the absolute value of those*/             for(int i = 1; i < n; i++){                 diff = abs(numbers[i] - numbers[i - 1]);                 differences.push_back(diff);             }              /*Sorting the differences in descending order*/             if(differences.size() > 1){                 sort(differences.begin(), differences.end(), greater<int>());             }              /*Creating a iterator for checking if the value reached one through n - 1*/             int k = n - 1;             for(int i = 0; i < differences.size(); i++){                 if(differences[i] == k){/*Tried the while loop here*/                     is_jolly = true;/*<-----This is where the problem is. If the difference at first is equal to k then it will not check again. I want it to check as long as the loop runs*/                 }else{                     is_jolly = false;                 }             k--;             } /*if is_jolly is true will print "Jolly" else "Not jolly"*/          }      } return 0; } 

The input is

1 2000 5 1 4 2 -1 6 2 1999 1998 4 1 4 2 3 4 1 3 2 -2 <---- Here I am getting Jolly instead of Not Jolly 4 1 4 3 5 4 1 2 5 7 3 4 1 3 4 1 4 2 3 4 1 2 3 6 <--- Here I am getting Jolly instead of Not Jolly 2 1 3 1 1 

Everything else works as expected.