Reason as to why code is malfunctioning? (Dynamic Programming)

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.

Here's what I've done so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 #include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace 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;
}
Last edited on
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 (==).



Last edited on
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.
Topic archived. No new replies allowed.