Why Doesn't This Work for 1343C?

Revision en1, by csotga, 2020-04-24 01:46:01

include <bits/stdc++.h>

using namespace std;

int main() { cin.tie(0); cout.tie(0); long long t; cin >> t; while(t--){ long long n; cin >> n; long long v [n]; long long sum; long long highestPositive; long long highestNegative; for(int i = 0; i<n; i++){ cin >> v[i]; }

if(v[0] > 0){
        highestPositive = v[0];
    }

    if(v[0] < 0){
        highestNegative = v[0];
    }

    for(int j = 1; j<n; j++){

        if(v[j-1] < 0 && v[j] > 0){
            sum = sum + highestNegative;
            highestPositive = v[j];
        }

        if(v[j-1] > 0 && v[j] < 0){
            sum = sum + highestPositive;
            highestNegative = v[j];
        }

        if(v[j-1] < v[j] < 0){
            highestNegative = v[j];
        }
        if(0 < v[j-1] < v[j]){
            highestPositive = v[j];
        }
    }

    if(v[n-1] > 0){
        sum = sum + highestPositive;
    }

    if(v[n-1] < 0){
        sum = sum + highestNegative;
    }

    cout << sum << "\n";
    sum = 0;
}

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English csotga 2020-04-24 01:48:28 1258
en1 English csotga 2020-04-24 01:46:01 1308 Initial revision (published)