ChallaAjay's blog

By ChallaAjay, history, 115 minutes ago, In English

Round 6.

Today's code is supposed to be pretty straightforward. We have an array of positive integers, and we need to find the sum of all its elements.

Nothing fancy. No segment trees, no DP, no 200-line template.

Just a loop.

The code

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int &x : a) cin >> x;

    int sum = 0;
    for (int x : a)
        sum += x;

    cout << sum << '\n';
}

Looks completely fine, doesn't it?

It compiles. It runs. It gives the correct answer on small examples.

But the constraints are:

  • 1 <= n <= 200000
  • 1 <= a[i] <= 1000000000

Your mission

Find a valid input for which this code fails.

  1. Give a counterexample that makes the output incorrect.
  2. Explain exactly what goes wrong.
  3. What's the smallest change needed to fix it?
  4. Bonus: can you explain why the same bug might go unnoticed during local testing?

Try to keep the counterexample small. No need to paste 200,000 numbers when a much smaller test can expose the problem.

Let's see who catches it first.

  • Vote: I like it
  • -4
  • Vote: I do not like it

»
110 minutes ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

at least try changing the name of the blog dude

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

    Sorry, What is wrong in that? please specify

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

      the answer is in the name

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

        So what do u guys recommend for the name?

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

          just remove part with the answer

»
55 minutes ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I'm gonna be honest. No one's interested in these blogs. Give us a harder challenge (or maybe some juicy rewards) and we'll try

»
3 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What is the point of all this?