The problem is quite simple really so just let me cut straight to the chase. You are given an even intenger N and N numbers following in the next line. You'll have to find the maximum size of a subset which contains the difference between two consecutive numbers from the initial set, and has the following rule: The even place should be a positive difference, and the odd place should be a negative difference.
Eg
12
3 1 5 7 8 8 2 2 10 8 6 7
{2, -2, 0, 0, 2, -1}
In this case, it is 2.
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
usingnamespace std;
int main(){
int n;
cin>>n;
n = n/2;
int diff[n];
int a, b;
for (int j=0; j<n; j++){
cin>>a>>b;
diff[j] = a - b;
}
bool checked[n];
for (int i=0; i<n; i++){
checked[i] = false;
}
int place = 0;
int counter = 0;
int maximum = 0;
while (checked[n-1] = false){
while (diff[place]>0 && diff[place+1]<0){
checked[place] = true;
checked[place+1] = true;
place=place+2;
counter++;
}
if (counter>maximum){
maximum = counter;
}
counter = 0;
place++;
checked[place] = true;
}
cout<<maximum;
}
Line 10, 16: These lines are not valid C++. The C++ standard requires that array dimensions be known at compile time, although some compilers allow this as a non-standard extension.
Line 23: You're using the assignment operator (=). You want the equality operator (==).
How didn't I see that before o.O? I should've noticed the operator..
and btw, my compiler has extensions for this, I wouldn't have done this if my compiler didn't.