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 <= 2000001 <= a[i] <= 1000000000
Your mission
Find a valid input for which this code fails.
- Give a counterexample that makes the output incorrect.
- Explain exactly what goes wrong.
- What's the smallest change needed to fix it?
- 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.








at least try changing the name of the blog dude
Sorry, What is wrong in that? please specify
the answer is in the name
So what do u guys recommend for the name?
just remove part with the answer
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