0
#include <iostream>
#include <vector>

using namespace std;

long long n;
long long s;

int main(){
    cin>>n;
    vector<long long>a(n);
    
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    for(long long i=1;i<=n;i=i+2){
        s+=a[i]-a[i+1];
    }

    cout<<s;
    
    return 0;
}

When I run the above code in Code::Blocks, it runs normally.

But when I paste to judge, it says:

Compiled Successfully. memory: 3524 time: 0.36 exit code: 134

and it has no output.

I tried to run on Ideone and online GDB, but same result.

How does this work?

3
  • That's SIGABRT. Surely caused by indexing the vector out-of-bounds, valid indices are 0..n-1 Commented Jul 12 at 20:50
  • for(long long i=1 - the first element is at index 0, not 1. Why do you start your loop at index 1? Commented Jul 12 at 23:42
  • "But when I paste to judge, it says" - Don't waste your time on online judges and/or competitive coding websites. You are just wasting your time for no gain. Commented Jul 13 at 0:05

0

Browse other questions tagged or ask your own question.