bdub's blog

By bdub, 12 years ago, In English

I am running this solution for 264 Div 2 B and am getting the correct response (4) for problem one, but when I submit it I'm get back "Wrong answer problem 1" and it's telling me the program is returning 0. I've trying unsuccessfully submitting under all three C++ options but I'm not sure why the online grader is returning a different answer than what I get when I run it on my computer here.... can anyone please help me?

include <stdio.h>

include <stdlib.h>

include <stdarg.h>

include <math.h>

include

include

typedef long long ll; typedef unsigned char byte; using namespace std;

int main(int argc, char* argv[]) {

ll n, x, y=0, ret=0, e=0;
vector<ll> vll;

cin >> n;

for (int i =0; i < n; ++i) {
    cin >> x;
    vll.push_back(x);
}

for (int i = 0; i < vll.size(); ++i) {
    x = vll[i];
    e += x-y;
    if (e < 0) {
            ret += abs(e);
            e=0;
    }
    y=x;
}

cout << ret << endl;
return 7;

}

Thanks!!

Tags c++
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
12 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Well why do you return 7 in main method?

  • »
    »
    12 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    No reason, just was making sure the online grader wasn't pulling it's answer from my return rather than from the cout... was a long shot but had to make sure

»
12 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
for (int i = 0; i < vll.size(); ++i) {
    x = vll[i];
    e += x-y;
    if (e < 0) {
            ret += abs(e);
            e=0;
    }
    y=x;
}

Statement says about difference in bits between one and all others, not near ones.

And, yes, return 0

P.S. surround your code with 5 tildas:

text

5 ~
code
5 ~

text
»
12 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

use smth like pasteubuntu to share your code