#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
Auto comment: topic has been updated by Gwazy (previous revision, new revision, compare).
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.You cannot mix
scanf
andcin
once you useios_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 theIOS
, 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
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;
withscanf("%d", &n);
and check.This might clarify things related to mixed C-style and C++-style IO.
Oh, I see!! Thanks guys!