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, 2024 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, 2024 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, 2024 at 0:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.