Amir_20's blog

By Amir_20, history, 10 years ago, In English

hi(){ excuse me for my trivial question ; can anyone help me and say what's the problem for the answer of "588c" (duff and lifting weights ) ?! ; }

include

using namespace std; int main(){ long n, i, a, m[1001000], b = 0, c = 0;

cin >> n;

for (i = 0; i < n; i++){
    cin >> a;
    m[a]++;
    if (c < a);
       c = a;
}
for (i = 0; i < c; i++){
    m[i] = m[i] % 2;
    m[i + 1] += m[i] / 2;
}
for (i = 0; i < c + 10; i++){
    if (m[i] != 0)
       b++;
}
cout << b;

}

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
10 years ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

In first, don't use semicolon after "if (c < a)". Because in your variant in c last item, but not max. Also, if you want use c, you should use "c+20" in loops, but not "c+10" and not just "c".