### Gwazy's blog

By Gwazy, history, 4 weeks ago, ,

29A - Spit Problem

#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int main() {
IOS

int n;
cin >> n;
int x[n], d[n];
x[0] = 0;
d[0] = 0;

for(int i = 0; i < n; i++){
scanf("%d", &x[i]);
scanf("%d", &d[i]);
}

for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if ((x[i] + d[i]) == x[j]) {
if(x[j] + d[j] == x[i]) {
cout << "YES";
return 0;
}
}
}
}
cout << "NO";
return 0;
}


Hey Code Forcers, I'm running this code on my terminal, and I'm getting a correct output for all tests.

However, when I submit the code to CodeForces, I fail test case two.

Initially, I was getting an uninitialized value usage before I initialised arrays x and d, could it be related?

I would appreciate any help,

Thanks

• -2

 » 4 weeks ago, # |   +1 Auto comment: topic has been updated by Gwazy (previous revision, new revision, compare).
 » 4 weeks ago, # |   +9 Don't mix cin and scanf, if you use sync_with_stdio(false). Either stick to one of these, or don't turn off sync_with_stdio.
 » 4 weeks ago, # | ← Rev. 2 →   +3 You cannot mix scanf and cinonce you use ios_base:: sync_with_studio(false) in your code. That is the thing which is giving you the wrong answer. I submitted the same code removing the IOS, and you can have a look at it 86608563. For more information you can also look at this blog. Updated: Thanks for the clarification dmitry.dolgopolov
•  » » 4 weeks ago, # ^ | ← Rev. 4 →   +9 It seems you misunderstand what sync_with_stdio(false) does. One can use scanf/printf with that but should not mix them with cin/cout. If you do not believe me, just replace cin >> n; with scanf("%d", &n); and check.This might clarify things related to mixed C-style and C++-style IO.
 » 4 weeks ago, # |   +1 Oh, I see!! Thanks guys!