text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; void merge(int *arr, int low, int mid, int high) { int i, j, b[high - low + 1], k; i = low; j = mid + 1; k = 0; while (i <= mid && j <= high) { if (arr[i] < arr[j]) b[k++] = arr[i++]; else b[k++] = arr[j++]; } if (i > mid) { while (j <= high) b[k++] = arr[j++]; } else { while (i <= mid) b[k++] = arr[i++]; } for (i = 0, j = low; i < k; i++, j++) arr[j] = b[i]; } void merge_sort(int *arr, int low, int high) { int mid = (low + high) / 2; if (low < high) { merge_sort(arr, low, mid); merge_sort(arr, mid + 1, high); merge(arr, low, mid, high); } } int main() { int j, i, n, arr[100001], b[100001]; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i < n - 1; i++) cin >> b[i]; merge_sort(arr, 0, n - 1); merge_sort(b, 0, n - 2); int cnt = 0; for (i = 0, j = 0; j < n - 1; i++, j++) { if (arr[i] != b[j]) { cout << arr[i] << " "; cnt++; j--; } } if (cnt == 0) cout << arr[n - 1] << " "; for (i = 0; i < n - 2; i++) cin >> arr[i]; merge_sort(arr, 0, n - 3); cnt = 0; for (i = 0, j = 0; j < n - 2; i++, j++) { if (b[i] != arr[j]) { cout << b[i] << " "; cnt++; j--; } } if (cnt == 0) cout << b[n - 2] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000001], b[1000001], c[1000001]; int main() { int n, i, x = 0, y = 0; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n - 1; i++) cin >> b[i]; for (i = 1; i <= n - 2; i++) cin >> c[i]; for (i = 1; i <= n; i++) { x += a[i]; x -= b[i]; } for (i = 1; i <= n - 1; i++) { y += b[i]; y -= c[i]; } cout << x << "\n" << y; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; ; int arr1[n]; int arr2[n - 1]; int arr3[n - 2]; int a = 0; int b = 0; int c = 0; for (int i = 0; i < n; i++) { cin >> arr1[i]; a += arr1[i]; } for (int i = 0; i < n - 1; i++) { cin >> arr2[i]; b += arr2[i]; } for (int i = 0; i < n - 2; i++) { cin >> arr3[i]; c += arr3[i]; } cout << a - b << "\n"; cout << b - c; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1.0); const int MOD = 1000 * 1000 * 1000 + 7; const int INF = 2000 * 1000 * 1000; template <typename T> inline T sqr(T n) { return n * n; } int n, x; long long a, b, c; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); a += x; } for (int i = 0; i < n - 1; i++) { scanf("%d", &x); b += x; } for (int i = 0; i < n - 2; i++) { scanf("%d", &x); c += x; } printf("%I64d\n%I64d\n", a - b, b - c); return 0; }
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int errors[n], errors2[n - 1], errors3[n - 2], sum1 = 0, sum2 = 0, sum3 = 0; int cnt = 0; for (int i = 0; i < n; i++) { scanf("%d", &errors[i]); sum1 += errors[i]; } for (int i = 0; i < n - 1; i++) { scanf("%d", &errors2[i]); sum2 += errors2[i]; } for (int i = 0; i < n - 2; i++) { scanf("%d", &errors3[i]); sum3 += errors3[i]; } printf("%d\n", abs(sum2 - sum1)); printf("%d\n", abs(sum3 - sum2)); }
#include <bits/stdc++.h> using namespace std; int main() { int i, n, a, suma = 0, sumb = 0, sumc = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); suma += a; } for (i = 0; i < n - 1; i++) { scanf("%d", &a); sumb += a; } for (i = 0; i < n - 2; i++) { scanf("%d", &a); sumc += a; } printf("%d\n", suma - sumb); printf("%d\n", sumb - sumc); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum1 = 0, sum2 = 0, ans1, ans2; long long int c; cin >> n; for (long long int i = 0; i < n; i++) { cin >> c; sum1 += c; } for (long long int i = 0; i < n - 1; i++) { cin >> c; sum2 += c; } ans1 = sum1 - sum2; sum1 = 0; for (long long int i = 0; i < n - 2; i++) { cin >> c; sum1 += c; } ans2 = sum2 - sum1; cout << ans1 << endl; cout << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; long long int binary_search(long long int ar[], int lb, int ub, long long int data); int main() { long long int n, first, last; cin >> n; long long int a, b, c, counta = 0, countb = 0, countc = 0; for (int i = 0; i < n; i++) { cin >> a; counta += a; } for (int i = 0; i < n - 1; i++) { cin >> b; countb += b; } for (int i = 0; i < n - 2; i++) { cin >> c; countc += c; } first = counta - countb; last = countb - countc; cout << first << endl << last << endl; counta = 0; countb = 0; countc = 0; return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; int a[M]; int b[M]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n - 1; i++) scanf("%d", &b[i]); sort(a, a + n); sort(b, b + n - 1); int i; for (i = 0; i < n - 1; i++) { if (a[i] != b[i]) break; } printf("%d\n", a[i]); for (i = 0; i < n - 2; i++) scanf("%d", &a[i]); sort(a, a + n - 2); for (i = 0; i < n - 2; i++) { if (b[i] != a[i]) break; } printf("%d\n", b[i]); }
#include <bits/stdc++.h> using namespace std; int main() { int n, *arr, *arr1, *arr2, ans1, ans2; cin >> n; arr = (int *)malloc(n * sizeof(int)); arr1 = (int *)malloc((n - 1) * sizeof(int)); arr2 = (int *)malloc((n - 2) * sizeof(int)); for (int x = 0; x < n; x++) { cin >> arr[x]; } sort(arr, arr + n); for (int x = 0; x < n - 1; x++) { cin >> arr1[x]; } sort(arr1, arr1 + n - 1); for (int x = 0; x < n - 2; x++) { cin >> arr2[x]; } sort(arr2, arr2 + n - 2); for (int x = 0; x < n; x++) { if (arr[x] != arr1[x]) { ans1 = arr[x]; break; } } for (int x = 0; x < n - 1; x++) { if (arr1[x] != arr2[x]) { ans2 = arr1[x]; break; } } cout << ans1 << "\n" << ans2; }
#include <bits/stdc++.h> using namespace std; int n, m, k; bool usd[10000]; int main() { cin >> n; long long a = 0, b = 0, c = 0; for (int i = 0; i < n; ++i) { int x; cin >> x; a += x; } for (int i = 0; i < n - 1; ++i) { int x; cin >> x; b += x; } for (int i = 0; i < n - 2; ++i) { int x; cin >> x; c += x; } cout << a - b << '\n' << b - c; }
#include <bits/stdc++.h> using namespace std; int a[1000000], b[1000000], c[1000000]; int main() { int n, ans1, ans2; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { cin >> b[i]; } for (int i = 0; i < n - 2; i++) { cin >> c[i]; } sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); for (int i = 0; i < n; i++) { if (a[i] != b[i]) { ans1 = a[i]; break; } } for (int i = 0; i < n - 1; i++) { if (b[i] != c[i]) { ans2 = b[i]; break; } } cout << ans1 << endl << ans2; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); long long tc = 1; while (tc--) { long long n; cin >> n; unordered_map<long long, long long> cnt; vector<long long> a(n), b(n - 1); for (auto &x : a) { cin >> x; cnt[x]++; } for (auto &x : b) { cin >> x; cnt[x]--; } for (auto xy : cnt) if (xy.second == 1) { cout << xy.first << '\n'; cnt[xy.first]--; } for (auto &x : b) { cnt[x]++; } for (long long i = 0; i < n - 2; i++) { long long x; cin >> x; cnt[x]--; } for (auto xy : cnt) if (xy.second == 1) { cout << xy.first << '\n'; cnt[xy.first]--; } } return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int b[n - 1]; for (int i = 0; i < n - 1; i++) { cin >> b[i]; } sort(b, b + n - 1); int c[n - 2]; for (int i = 0; i < n - 2; i++) { cin >> c[i]; } sort(c, c + n - 2); for (int i = 0; i < n - 1; i++) { if (a[i] != b[i]) { cout << a[i] << endl; break; } if (i == n - 2) { cout << a[n - 1] << endl; } } for (int i = 0; i < n - 2; i++) { if (c[i] != b[i]) { cout << b[i] << endl; break; } if (i == n - 3) { cout << b[n - 2]; } } }
#include <bits/stdc++.h> using namespace std; int a[100009], b[100009]; int n, m, an1, an2; map<int, int> x, y; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; x[a[i]]++; } for (int i = 1; i < n; i++) { cin >> b[i]; y[b[i]]++; x[b[i]]--; } for (int i = 2; i < n; i++) { int c; cin >> c; y[c]--; } for (int i = 0; i < n; i++) { if (x[a[i]] > 0) { an1 = a[i]; break; } } for (int i = 1; i < n; i++) { if (y[b[i]] > 0) { an2 = b[i]; break; } } cout << an1 << endl << an2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long a, b, c; long long sum = 0, nu1, nu2; for (int i = 0; i < n; i++) { cin >> a; sum += a; } long long su1 = 0; for (int i = 0; i < n - 1; i++) { cin >> b; su1 += b; } long long x = sum - su1; cout << x << endl; su1 = 0; for (int i = 0; i < n - 2; i++) { cin >> c; su1 += c; } sum -= x; cout << sum - su1; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100005], b[100005], c[100005]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); cin >> n; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n - 1; i++) scanf("%d", &b[i]); for (int i = 0; i < n - 2; i++) scanf("%d", &c[i]); sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); int j = 0, k = 0, ci, bi; for (int i = 0; i < n; i++) if (a[i] == b[j]) { j++; if (a[i] == c[k]) k++; else ci = a[i]; } else bi = a[i]; cout << bi << endl << ci; }
#include <bits/stdc++.h> int main() { long long n; long long f1 = 0, f2 = 0, f3 = 0; long long err = 0, err2 = 0; scanf("%lld", &n); for (int i = 0; i < n; i++) { scanf("%lld", &err); f1 += err; } for (int i = 0; i < n - 1; i++) { scanf("%lld", &err); f2 += err; } printf("%lld\n", f1 - f2); for (int i = 0; i < n - 2; i++) { scanf("%lld", &err); f3 += err; } printf("%lld", f2 - f3); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int a[n], b[n - 1], c[n - 2]; int s1 = 0, s2 = 0, s3 = 0; for (i = 0; i < n; i++) { cin >> a[i]; s1 += a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; s2 += b[i]; } for (i = 0; i < n - 2; i++) { cin >> c[i]; s3 += c[i]; } cout << s1 - s2 << endl; cout << s2 - s3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, res1, res2; int f[100001]; int s[100001]; int t[100001]; void solve() { int sumf = 0, sums = 0, sumt = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> f[i]; sumf += f[i]; } for (int i = 0; i < n - 1; i++) { cin >> s[i]; sums += s[i]; } res1 = sumf - sums; for (int i = 0; i < n - 2; i++) { cin >> t[i]; sumt += t[i]; } res2 = sums - sumt; cout << res1 << "\n" << res2 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '"' << x << '"'; } void __print(const string &x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } vector<int> input(int n) { vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; return a; } vector<long long int> input_lli(int n) { vector<long long int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; return a; } void print(vector<int> arr) { for (int i = 0; i < arr.size(); ++i) cout << arr[i] << ' '; cout << endl; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; map<int, int> arr1; map<int, int> arr2; map<int, int> arr3; for (int i = 0; i < n; ++i) { int a; cin >> a; ++arr1[a]; } for (int i = 0; i < n - 1; ++i) { int a; cin >> a; ++arr2[a]; } for (int i = 0; i < n - 2; ++i) { int a; cin >> a; ++arr3[a]; } for (auto x : arr1) { if (x.second != arr2[x.first]) cout << x.first << endl; } for (auto x : arr2) { if (x.second != arr3[x.first]) cout << x.first << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; long long int sum = 0; long long int sum1 = 0; long long int sum2 = 0; int temp; for (int i = 0; i < n; i++) { cin >> temp; sum += temp; } for (int i = 0; i < n - 1; i++) { cin >> temp; sum1 += temp; } sum = sum - sum1; for (int i = 0; i < n - 2; i++) { cin >> temp; sum2 += temp; } sum2 = sum1 - sum2; cout << sum << '\n' << sum2; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { multiset<int> x, x2; multiset<int>::iterator it; int n, k; cin >> n; for (int i = 0; i < n; i++) { cin >> k; x.insert(k); } for (int i = 0; i < n - 1; i++) { cin >> k; x2.insert(k); it = x.find(k); x.erase(it); } for (it = x.begin(); it != x.end(); ++it) cout << *it << "\n"; for (int i = 0; i < n - 2; i++) { cin >> k; it = x2.find(k); if (it != x2.end()) x2.erase(it); } for (it = x2.begin(); it != x2.end(); ++it) cout << *it << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n - 1], c[n - 2]; int i; int suma = 0, sumb = 0, sumc = 0; for (i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; sumb += b[i]; } for (i = 0; i < n - 2; i++) { cin >> c[i]; sumc += c[i]; } cout << suma - sumb << "\n" << sumb - sumc; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int s1 = 0, s2 = 0, s3 = 0, n, i, a, b; cin >> n; long long int k[n]; long long int l[n - 1]; long long int m[n - 2]; for (i = 0; i < n; i++) { cin >> k[i]; s1 = s1 + k[i]; } for (i = 0; i < n - 1; i++) { cin >> l[i]; s2 = s2 + l[i]; } for (i = 0; i < n - 2; i++) { cin >> m[i]; s3 = s3 + m[i]; } cout << s1 - s2 << endl << s2 - s3; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long a = 0, b = 0, c = 0; int cnt = 0; vector<long long> ar(n), ar1(n - 1), ar2(n - 2); for (int i = 0; i < n; i++) { cin >> ar[i]; a += ar[i]; } for (int i = 0; i < n - 1; i++) { cin >> ar1[i]; b += ar1[i]; } for (int i = 0; i < n - 2; i++) { cin >> ar2[i]; c += ar2[i]; } cout << a - b << endl << b - c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k; cin >> n; long long a[n], b[n - 1], c[n - 2]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; } for (i = 0; i < n - 2; i++) { cin >> c[i]; } sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); long long first = -1, second = -1; for (i = 0; i < n - 1; i++) { if (a[i] != b[i]) { first = a[i]; break; } } if (first == -1) { first = a[n - 1]; } for (i = 0; i < n - 2; i++) { if (b[i] != c[i]) { second = b[i]; break; } } if (second == -1) { second = b[n - 2]; } cout << first << "\n" << second << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; int b[a + 1], c[a + 1], d[a + 1]; for (int i = 0; i < a; i++) { cin >> b[i]; } for (int i = 0; i < a - 1; i++) { cin >> c[i]; } for (int i = 0; i < a - 2; i++) { cin >> d[i]; } sort(b, b + a); sort(c, c + a - 1); c[a] = -1; d[a - 1] = -1; sort(d, d + a - 2); for (int i = 0; i < a; i++) { if (b[i] != c[i]) { cout << b[i] << endl; break; } } for (int i = 0; i < a - 1; i++) { if (c[i] != d[i]) { cout << c[i] << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n - 1], c[n - 2]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = 0; i < n - 2; i++) cin >> c[i]; sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); int i = 0; for (i = 0; i < n - 1; i++) { if (a[i] != b[i]) { cout << a[i] << "\n"; break; } else continue; } if (i == n - 1) cout << a[i] << "\n"; i = 0; for (i = 0; i < n - 2; i++) { if (b[i] != c[i]) { cout << b[i] << "\n"; break; } } if (i == n - 2) cout << b[i] << "\n"; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int N = 1e5 + 5; int a[N], b[N], ans1, ans2, n; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n - 1; ++i) cin >> b[i]; sort(a, a + n); sort(b, b + n - 1); for (int i = 0; i < n - 1; ++i) if (a[i] != b[i]) { ans1 = a[i]; break; } if (!ans1) ans1 = a[n - 1]; for (int i = 0; i < n - 2; ++i) cin >> a[i]; sort(a, a + n - 2); for (int i = 0; i < n - 2; ++i) if (b[i] != a[i]) { ans2 = b[i]; break; } if (!ans2) ans2 = b[n - 2]; cout << ans1 << endl << ans2; return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); } int n; vector<int> vv, vv1, vv2; int main() { ios_base::sync_with_stdio(false); cin >> n; long long tt; for (int i = 0; i < n; i++) { cin >> tt; vv.push_back(tt); } sort(vv.begin(), vv.end()); for (int i = 0; i < n - 1; i++) { cin >> tt; vv1.push_back(tt); } vv1.push_back(1000000005); sort(vv1.begin(), vv1.end()); for (int i = 0; i < n - 2; i++) { cin >> tt; vv2.push_back(tt); } vv2.push_back(1000000005); vv1.push_back(1000000006); sort(vv2.begin(), vv2.end()); for (int i = 0; i < n; i++) { if (vv[i] == vv1[i]) { } else { cout << vv[i] << endl; break; } } for (int i = 0; i < n - 1; i++) { if (vv2[i] == vv1[i]) { } else { cout << vv1[i] << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a = 0, b = 0, c = 0; int count = 0; for (int j = 0; j <= 2; j++) { int arr[n]; count++; for (int i = 0; i < n; i++) { cin >> arr[i]; if (count == 1) a = a + arr[i]; else if (count == 2) b = b + arr[i]; else c = c + arr[i]; } n--; } cout << a - b << endl; cout << b - c << endl; }
#include <bits/stdc++.h> using namespace std; list<int> l1, l2, l3, l4; int main() { int n, t, a, c; cin >> n; for (int i = 0; i < n; i++) { cin >> t; l1.push_back(t); } for (int i = 0; i < n - 1; i++) { cin >> t; l2.push_back(t); l4.push_back(t); } for (int i = 0; i < n - 2; i++) { cin >> t; l3.push_back(t); } l1.sort(); l2.sort(); l3.sort(); l4.sort(); for (list<int>::iterator it = l1.begin(), itr = l2.begin(); it != l1.end(); it++, itr++) { if (*it != *itr) { a = *it; break; } } for (list<int>::iterator it = l4.begin(), itr = l3.begin(); it != l4.end(); it++, itr++) { if (*it != *itr) { c = *it; break; } } cout << a << endl << c << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n - 1], c[n - 2]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = 0; i < n - 2; i++) cin >> c[i]; sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); int s1, s2; bool flag = true; for (int i = 0; i < n - 1; i++) { if (a[i] != b[i]) { s1 = a[i]; flag = false; break; } } if (flag) s1 = a[n - 1]; flag = true; for (int i = 0; i < n - 2; i++) { if (b[i] != c[i]) { s2 = b[i]; flag = false; break; } } if (flag) s2 = b[n - 2]; cout << s1 << '\n' << s2 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const long long ooll = (long long)1e18; int n; int v1[1234567], v2[1234567], v3[1234567]; int main() { scanf("%i", &n); for (int i = 0; i < n; ++i) { scanf("%i", v1 + i); } for (int i = 0; i < n - 1; ++i) { scanf("%i", v2 + i); } for (int i = 0; i < n - 2; ++i) { scanf("%i", v3 + i); } sort(v1, v1 + n); sort(v2, v2 + n - 1); sort(v3, v3 + n - 2); int x = v1[n - 1], y = v2[n - 2]; for (int i = 0; i < n - 1; ++i) { if (v1[i] != v2[i]) { x = v1[i]; break; } } for (int i = 0; i < n - 2; ++i) { if (v2[i] != v3[i]) { y = v2[i]; break; } } cout << x << " " << y; return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> A, B, C; vector<int> vec; int main() { int n; cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; vec.push_back(x); if (A.find(x) != A.end()) { ++A[x]; } else A[x] = 1; } for (int i = 0; i < n - 1; i++) { cin >> x; if (B.find(x) != B.end()) { ++B[x]; } else B[x] = 1; } for (int i = 0; i < n - 2; i++) { cin >> x; if (C.find(x) != C.end()) { ++C[x]; } else C[x] = 1; } int res_1 = -1, res_2 = -1; int id; for (int i = 0; i < n; i++) { id = vec[i]; if (B.find(id) == B.end() || B[id] < A[id]) { res_1 = id; } if ((C.find(id) == C.end() && B.find(id) != B.end()) || C[id] < B[id]) { res_2 = id; } } cout << res_1 << endl; cout << res_2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, x, y, a1[100010], a2[100010], a3[100010], a4[100010]; cin >> n; vector<int> v; for (i = 0; i < n; i++) cin >> a1[i]; for (i = 0; i < n; i++) a4[i] = a1[i]; sort(a1, a1 + n); for (i = 0; i < n - 1; i++) cin >> a2[i]; sort(a2, a2 + n - 1); for (i = 0; i < n - 2; i++) cin >> a3[i]; sort(a3, a3 + n - 2); for (i = 0, j = 0; i < n; i++) { if (a1[i] == a2[j]) j++; else v.push_back(a1[i]); } for (i = 0, j = 0; i < n - 1; i++) { if (a2[i] == a3[j]) j++; else v.push_back(a2[i]); } for (i = 0; i < v.size(); i++) cout << v[i] << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX = 133331; struct hashNode { int numVal; int numCnt; int test; hashNode() : numVal(0), numCnt(0) {} }; hashNode hashTable[MAX]; void insert(int x) { int pos = x % MAX; while (hashTable[pos].numVal != 0 && hashTable[pos].numVal != x) { pos++; if (pos > MAX) pos -= MAX; } if (hashTable[pos].numVal == 0) { hashTable[pos].numVal = x; hashTable[pos].numCnt = 1; } else hashTable[pos].numCnt++; } void check(int x) { int pos = x % MAX; while (hashTable[pos].numVal != 0 && hashTable[pos].numVal != x) { pos++; if (pos > MAX) pos -= MAX; } hashTable[pos].test--; } int main() { int n, i, j, a; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a); insert(a); } for (i = 0; i <= MAX - 1; i++) hashTable[i].test = hashTable[i].numCnt; for (i = 1; i <= n - 1; i++) { scanf("%d", &a); check(a); } for (i = 0; i <= MAX - 1; i++) { if (hashTable[i].test) { cout << hashTable[i].numVal << ' '; hashTable[i].numCnt--; } } for (i = 0; i <= MAX - 1; i++) hashTable[i].test = hashTable[i].numCnt; for (i = 1; i <= n - 2; i++) { scanf("%d", &a); check(a); } for (i = 0; i <= MAX - 1; i++) { if (hashTable[i].test) { cout << hashTable[i].numVal << ' '; hashTable[i].numCnt--; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long INF = 1e6; long long M = 1e9 + 7; void solve() { long long n; cin >> n; vector<int> a(n), b(n - 1), c(n - 2); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = 0; i < n - 2; i++) cin >> c[i]; sort((a).begin(), (a).end()); sort((b).begin(), (b).end()); sort((c).begin(), (c).end()); long long x, y; bool f1 = true, f2 = true; for (int i = 0; i < n - 1; i++) { if (i < n - 2 && f2) { if (b[i] != c[i]) { y = b[i]; f2 = false; } } if (a[i] != b[i] && f1) { x = a[i]; f1 = false; } } if (f1) x = a[n - 1]; if (f2) y = b[n - 2]; cout << x << "\n" << y << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, k, l, t, s, a, cnt = 0, a1[1005], a2[1005], a3[1005], lb, ub, mid, mx, v; long long s1 = 0, s2 = 0, s3 = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a; s1 += a; } for (i = 0; i < n - 1; i++) { cin >> a; s2 += a; } for (i = 0; i < n - 2; i++) { cin >> a; s3 += a; } cout << s1 - s2 << endl; cout << s2 - s3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (auto &i : v) cin >> i; int x = v[0]; int temp; for (int i = 1; i < n; i++) x = x ^ v[i]; int y = x; for (int i = 0; i < n - 1; i++) { cin >> temp; y = y ^ temp; } int first = y; cout << first << endl; y = x; for (int i = 0; i < n - 2; i++) { cin >> temp; y = y ^ temp; } int second = y ^ first; cout << second << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, ara[100000], temp[100000], tm = 0, ans[5], i, j, c = 0; stack<int> a; tm = c; cin >> n; for (i = 0; i < 3; i++) { for (j = 0; j < n - i; j++) { cin >> ara[j]; } sort(ara, ara + (n - i)); if (i != 0) { for (j = 0; j < n - i; j++) { if (temp[j] != ara[j]) { ans[c] = temp[j]; c++; break; } } if (c == tm) { if (i == 1) { ans[c] = temp[n - 1]; c++; tm = c; } else { ans[c] = temp[n - 2]; c++; tm = c; } } else { tm = c; } } for (j = 0; j < n - i; j++) { temp[j] = ara[j]; } } for (i = 0; i < 2; i++) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<long long> s, s1; cin >> n; long long a[n], b[n - 1], c[n - 2]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = 0; i < n - 2; i++) cin >> c[i]; sort(a, a + n); sort(b, b + n - 1); sort(c, c + n - 2); for (int i = 0; i < n; i++) if (i == n - 1 || a[i] != b[i]) { cout << a[i] << endl; break; } for (int i = 0; i < n - 1; i++) if (i == n - 2 || b[i] != c[i]) { cout << b[i] << endl; break; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long xr1 = 0, xr2 = 0; for (int i = 0; i < n; i++) { long long s; cin >> s; xr1 = xr1 ^ s; } for (int i = 0; i < n - 1; i++) { long long s; cin >> s; xr2 = xr2 ^ s; xr1 = xr1 ^ s; } cout << xr1 << endl; for (int i = 0; i < n - 2; i++) { long long s; cin >> s; xr2 = xr2 ^ s; } cout << xr2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, b = 0, c = 0, x; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &x); a ^= x; } for (int i = 0; i < n - 1; ++i) { scanf("%d", &x); b ^= x; } for (int i = 0; i < n - 2; ++i) { scanf("%d", &x); c ^= x; } printf("%d\n%d", a ^ b, b ^ c); }
#include <bits/stdc++.h> using namespace std; const int Z = (int)1e5 + 13; const int inf = (int)1e9 + 13; const long long llinf = (long long)1e18 + 13; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a += x; } for (int i = 0; i < n - 1; i++) { int x; cin >> x; b += x; } for (int i = 0; i < n - 2; i++) { int x; cin >> x; c += x; } cout << a - b << ' ' << b - c; return 0; }
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int sum1 = 0, sum2 = 0, sum3 = 0, num; for (int i = 0; i < n; i++) { scanf("%d", &num); sum1 += num; } for (int i = 0; i < n - 1; i++) { scanf("%d", &num); sum2 += num; } for (int i = 0; i < n - 2; i++) { scanf("%d", &num); sum3 += num; } printf("%d\n%d", sum1 - sum2, sum2 - sum3); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long arr1[n], arr2[n], arr3[n]; for (int i = 0; i < n; i++) { cin >> arr1[i]; } for (int i = 0; i < n - 1; i++) { cin >> arr2[i]; } for (int i = 0; i < n - 2; i++) { cin >> arr3[i]; } sort(arr1, arr1 + n); sort(arr2, arr2 + n - 1); sort(arr3, arr3 + n - 2); for (int i = 0; i < n; i++) { if (arr1[i] != arr2[i]) { cout << arr1[i] << "\n"; break; } } for (int i = 0; i < n - 1; i++) { if (arr2[i] != arr3[i]) { cout << arr2[i] << "\n"; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long A[100010], AA[100010], AAA[100010]; int main() { long long N; scanf("%I64d", &N); for (int I = 0; I < N; I++) { scanf("%I64d", &A[I]); } for (int I = 0; I < N - 1; I++) { scanf("%I64d", &AA[I]); } for (int I = 0; I < N - 2; I++) { scanf("%I64d", &AAA[I]); } sort(A, A + N); sort(AA, AA + N - 1); sort(AAA, AAA + N - 2); bool B = 0; for (int I = 0; I < N - 1; I++) { if (A[I] != AA[I]) { printf("%I64d\n", A[I]); B = 1; break; } } if (!B) printf("%I64d\n", A[N - 1]); B = 0; for (int I = 0; I < N - 2; I++) { if (AA[I] != AAA[I]) { printf("%I64d\n", AA[I]); B = 1; break; } } if (!B) printf("%I64d\n", AA[N - 2]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; map<int, int> a, b, c; map<int, int>::iterator it; for (int i = (int)1; i <= (int)n; i++) { cin >> x; a[x]++; } for (int i = (int)1; i <= (int)n - 1; i++) { cin >> x; b[x]++; } for (int i = (int)1; i <= (int)n - 2; i++) { cin >> x; c[x]++; } int u, v; for (it = a.begin(); it != a.end(); it++) { if (b[it->first] != a[it->first]) u = it->first; if (b[it->first] != c[it->first]) v = it->first; } cout << u << "\n" << v << endl; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; bool comp(int a, int b) { return (a < b); } int main() { int n; cin >> n; vector<long long> v(n), v1(n - 1), v2(n - 2); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n - 1; i++) cin >> v1[i]; for (int i = 0; i < n - 2; i++) cin >> v2[i]; sort(v.begin(), v.end()); sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); int i, c = 0; for (i = 0; i < n - 1; i++) { if (v[i] != v1[i]) { c = 1; break; } } if (c) cout << v[i] << "\n"; else cout << v[n - 1] << "\n"; int cc = 0; for (i = 0; i < n - 2; i++) { if (v1[i] != v2[i]) { cc = 1; break; } } if (cc) cout << v1[i]; else cout << v1[n - 2]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int i, n; cin >> n; long long int first[n], second[n - 1], third[n - 2]; for (i = 0; i < n; i++) cin >> first[i]; for (i = 0; i < n - 1; i++) cin >> second[i]; for (i = 0; i < n - 2; i++) cin >> third[i]; sort(first, first + n); sort(second, second + (n - 1)); sort(third, third + (n - 2)); long long int a = 0, b = 0; for (i = 0; i < n - 1; i++) { if (first[i] != second[i]) { a = first[i]; break; } } if (i == n - 1) a = first[i]; for (i = 0; i < n - 2; i++) { if (second[i] != third[i]) { b = second[i]; break; } } if (i == n - 2) b = second[i]; cout << a << endl; cout << b << endl; }
#include <bits/stdc++.h> using namespace std; int n, x; vector<int> v[3]; int main() { scanf("%d", &n); for (int i = 0; i < 3; i++) { for (int j = 0; j < n - i; j++) { scanf("%d", &x); v[i].push_back(x); } } for (int i = 0; i < 3; i++) { sort(v[i].begin(), v[i].end()); } v[1].push_back(0); v[2].push_back(0); v[2].push_back(0); for (int i = 0; i < 2; i++) { int in = 0; for (int j = 0; j < v[i].size(); j++) { if (v[i][j] == v[i + 1][in]) { in++; } else { printf("%d\n", v[i][j]); break; } } } }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, x; cin >> n; map<long long, long long> m, m1, m2; for (long long i = 0; i < n; i++) { cin >> x; m[x]++; } for (long long i = 0; i < n - 1; i++) { cin >> x; m1[x]++; } for (auto i : m) { if (m[i.first] != m1[i.first]) cout << i.first << "\n"; } for (long long i = 0; i < n - 2; i++) { cin >> x; m2[x]++; } for (auto i : m1) { if (m2[i.first] != m1[i.first]) cout << i.first << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[3], k; cin >> n; fill(a, a + 3, 0); for (int i = 0; i < 3; i++) { for (int j = 0; j < n - i; j++) { cin >> k; a[i] += k; } } cout << a[0] - a[1] << endl << a[1] - a[2]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, num, s1 = 0, s2 = 0, s3 = 0; cin >> n; for (int k = 0; k < n; k++) { cin >> num; s1 += num; } for (int k = 0; k < n - 1; k++) { cin >> num; s2 += num; } for (int k = 0; k < n - 2; k++) { cin >> num; s3 += num; } cout << s1 - s2 << endl; cout << s2 - s3 << endl; }
#include <bits/stdc++.h> using namespace std; const int infint = INT_MAX; const long long infll = LLONG_MAX; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; multiset<int> errs[3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < n - i; j++) { int v; cin >> v; errs[i].insert(v); } } int frst = 0; multiset<int> cp = errs[0]; for (auto i : errs[1]) { auto iter = cp.find(i); if (iter != cp.end()) cp.erase(iter); } frst = *cp.begin(); for (auto i : errs[2]) { auto iter = errs[1].find(i); if (iter != errs[1].end()) errs[1].erase(iter); } cout << frst << "\n" << *errs[1].begin(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; long f = 0, k = 0, p = 0; cin >> n; int a[n], b[n - 1], c[n - 2]; for (int i = 0; i < n; i++) { cin >> a[i]; f += a[i]; } for (int i = 0; i < n - 1; i++) { cin >> b[i]; k += b[i]; } for (int i = 0; i < n - 2; i++) { cin >> c[i]; p += c[i]; } cout << f - k << endl << k - p; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, s1 = 0, s2 = 0, s3 = 0, i; cin >> n; for (i = 0; i < n; i++) { cin >> k; s1 = s1 + k; } for (i = 0; i < n - 1; i++) { cin >> k; s2 = s2 + k; } for (i = 0; i < n - 2; i++) { cin >> k; s3 = s3 + k; } cout << s1 - s2 << endl << s2 - s3; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, z, k, sol, sum, ans, l, r, xx, yy, a[1000000], b[1000000], d[1000000], c[1000000]; vector<long long> v[2000]; vector<pair<long long, long long>> v1; vector<pair<long long, long long>> v2; pair<long long, pair<long long, long long>> pp[1000000]; pair<long long, long long> p[1000000]; map<long long, vector<long long>> ma; map<long long, long long> m1; map<long long, long long> m2; string s1, s2, s; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i], m1[a[i]]++; for (int i = 0; i < n - 1; i++) cin >> b[i], m2[b[i]]++; for (int i = 0; i < n - 2; i++) cin >> c[i]; for (int i = 0; i < n - 1; i++) m1[b[i]]--; for (int i = 0; i < n - 2; i++) m2[c[i]]--; for (int i = 0; i < n; i++) { if (m1[a[i]]) { x = a[i]; break; } } for (int i = 0; i < n - 1; i++) { if (m2[b[i]]) { y = b[i]; break; } } cout << x << " " << y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> a; for (int i = 0; i < n; i++) { int temp; cin >> temp; a[temp]++; } map<int, int> b; for (int i = 0; i < n - 1; i++) { int temp; cin >> temp; b[temp]++; } map<int, int> c; for (int i = 0; i < n - 2; i++) { int temp; cin >> temp; c[temp]++; } for (map<int, int>::iterator it = a.begin(); it != a.end(); ++it) { if (it->second != b[it->first]) { cout << it->first << endl; break; } } for (map<int, int>::iterator it = b.begin(); it != b.end(); ++it) { if (it->second != c[it->first]) { cout << it->first << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> cnt1, cnt2, cnt3; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); ++cnt1[x]; } for (int i = 1; i <= n - 1; ++i) { int x; scanf("%d", &x); ++cnt2[x]; } for (int i = 1; i <= n - 2; ++i) { int x; scanf("%d", &x); ++cnt3[x]; } for (map<int, int>::iterator it = cnt1.begin(); it != cnt1.end(); ++it) if (it->second != cnt2[it->first]) { printf("%d\n", it->first); break; } for (map<int, int>::iterator it = cnt2.begin(); it != cnt2.end(); ++it) if (it->second != cnt3[it->first]) { printf("%d", it->first); break; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main(int argc, char const *argv[]) { cin.sync_with_stdio(0); long long int n, x; scanf("%lld", &n); multiset<long long int> st, st1; for (int i = 0; i < n; ++i) { scanf("%lld", &x); st.insert(x); } st1.insert(st.begin(), st.end()); for (int i = 0; i < n - 1; ++i) { scanf("%lld", &x); st.erase(st.find(x)); } printf("%lld\n", (*st.begin())); st1.erase(st1.find(*st.begin())); for (int i = 0; i < n - 2; ++i) { scanf("%lld", &x); st1.erase(st1.find(x)); } printf("%lld\n", (*st1.begin())); }
#include <bits/stdc++.h> using namespace std; int main() { multiset<int> s1, s2; int n; cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; s1.insert(x); } for (int i = 0; i < n - 1; ++i) { int x; cin >> x; s2.insert(x); s1.erase(s1.find(x)); } cout << *s1.begin() << endl; for (int i = 0; i < n - 2; ++i) { int x; cin >> x; s2.erase(s2.find(x)); } cout << *s2.begin() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100000], b[100000], c[100000], i, p[2]; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n - 1; i++) { cin >> b[i]; } sort(b, b + n - 1); for (i = 0; i < n - 2; i++) { cin >> c[i]; } sort(c, c + n - 2); for (i = 0; i < n; i++) { if (a[i] != b[i]) { p[0] = a[i]; break; } } for (i = 0; i < n; i++) { if (b[i] != c[i]) { p[1] = b[i]; break; } } cout << p[0] << endl; cout << p[1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int temp, sum1 = 0, sum2 = 0, sum3 = 0; for (int i = 0; i < n; i++) { cin >> temp; sum1 += temp; } for (int i = 0; i < n - 1; i++) { cin >> temp; sum2 += temp; } for (int i = 0; i < n - 2; i++) { cin >> temp; sum3 += temp; } cout << sum1 - sum2 << endl << sum2 - sum3 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n), vn(n - 1), vnn(n - 2); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n - 1; i++) { cin >> vn[i]; } for (int i = 0; i < n - 2; i++) { cin >> vnn[i]; } sort(v.begin(), v.end()); sort(vn.begin(), vn.end()); sort(vnn.begin(), vnn.end()); for (int i = 0; i < n; i++) { if (v[i] != vn[i]) { cout << v[i] << endl; break; } } for (int i = 0; i < n - 1; i++) { if (vn[i] != vnn[i]) { cout << vn[i] << endl; break; } } }
#include <bits/stdc++.h> using namespace std; string s; string numtostring(float num) { stringstream stream; stream << fixed << setprecision(6) << num; s = stream.str(); return s; } int power(int a, int b) { int res = 1; while (b) { if (b % 2) { res = (res * a) % 1000000007; } b /= 2; a = (a * a) % 1000000007; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long i, n, m, p; cin >> n; m = n - 1; p = n - 2; int a[n], b[m], c[p]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) cin >> b[i]; for (i = 0; i < p; i++) cin >> c[i]; sort(a, a + n); sort(b, b + m); sort(c, c + p); for (i = 0; i < n; i++) { if (a[i] != b[i]) { cout << a[i] << "\n"; break; } } for (i = 0; i < m; i++) { if (b[i] != c[i]) { cout << b[i] << "\n"; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int sum1 = 0, sum2 = 0, sum3 = 0, n1, n2, n3; cin >> n1; n2 = n1 - 1; n3 = n2 - 1; int temp; while (n1--) { cin >> temp; sum1 += temp; } while (n2--) { cin >> temp; sum2 += temp; } while (n3--) { cin >> temp; sum3 += temp; } cout << sum1 - sum2 << "\n" << sum2 - sum3; int do_not_hack; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i; cin >> n; long long a[n], b[n - 1], c[n - 2]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + n - 1); for (i = 0; i < n - 1;) { if (a[i] != b[i]) { cout << a[i] << endl; break; } i++; } if (i == n - 1) { cout << a[n - 1] << endl; } for (i = 0; i < n - 2; i++) { cin >> c[i]; } sort(c, c + n - 2); for (i = 0; i < n - 2;) { if (b[i] != c[i]) { cout << b[i] << endl; break; } i++; } if (i == n - 2) { cout << b[n - 2] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { map<long, int> a, b; int v, i, n; cin >> n; for (i = 0; i < n; i++) { cin >> v; a[v]++; } for (i = 0; i < n - 1; i++) { cin >> v; a[v]--; b[v]++; } for (i = 0; i < n - 2; i++) { cin >> v; b[v]--; } map<long, int>::iterator it; for (it = a.begin(); it != a.end(); it++) { if (it->second == 1) cout << it->first << endl; } for (it = b.begin(); it != b.end(); it++) { if (it->second == 1) cout << it->first << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void file() {} const int MN = 1e9 + 1e2; const int MW = 1e3 + 5; const int OO = 1e9 + 5; int main() { file(); map<int, int> ar[3]; int v[3][(int)(1e5 + 100)]; int n, ms[3]; scanf("%d", &n); for (int i = 0; i < 3; ++i) for (int j = 0; j < n - i and scanf("%d", &v[i][j]); ++j) ar[i][v[i][j]]++; for (int i = 0; i < 2; ++i) for (int j = 0; j < n - i; ++j) if (ar[i][v[i][j]] != ar[i + 1][v[i][j]]) ms[i] = v[i][j]; printf("%d", ms[0]), printf("\n"), printf("%d", ms[1]); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = INT_MAX; const long long int LINF = LLONG_MAX; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, maxx = -INF, x, h, res = 0; cin >> n; pair<int, int> tree[n]; for (int i = 0; i < n; ++i) cin >> tree[i].first >> tree[i].second; for (int i = 0; i < n; ++i) { int cx = tree[i].first, ch = tree[i].second; if (cx - ch > maxx) { res++; maxx = cx; } else if (i == n - 1 || cx + ch < tree[i + 1].first) { res++; maxx = cx + ch; } else { maxx = cx; } } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; bool check_prime(long long n) { long long flag = 0; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { flag = 1; break; } } if (n == 1) return false; else if (flag == 0 || n == 2 || n == 3) { return true; } else { return false; } } long long BE(long long x, long long n, long long m) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = result * x % m; x = x * x % m; n = n / 2; } return result; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); long long n; cin >> n; long long x[n], h[n]; long long cnt = 2; for (long long i = 0; i < n; i++) { cin >> x[i] >> h[i]; } for (long long i = 1; i < n - 1; i++) { if (x[i] - x[i - 1] - 1 >= h[i]) { cnt++; } else if (x[i] + h[i] < x[i + 1]) { cnt++; x[i] += h[i]; } } if (n == 1) { cout << 1 << '\n'; } else cout << cnt << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; const int N = 110000; const double EPS = 1e-8; pair<int, int> p[N]; int n; int fromLeft() { auto ans = 2, prev = p[0].first; for (auto i = 1; i < n - 1; ++i) { auto cur = p[i]; if (cur.first - cur.second > prev) { ++ans; prev = cur.first; } else if (cur.first + cur.second < p[i + 1].first) { ++ans; prev = cur.first + cur.second; } else { prev = cur.first; } } return ans; } int fromRight() { auto ans = 2, next = p[n - 1].first; for (auto i = n - 2; i >= 1; --i) { auto cur = p[i]; if (cur.first + cur.second < next) { ++ans; next = cur.first; } else if (cur.first - cur.second > p[i - 1].first) { ++ans; next = cur.first - cur.second; } else { next = cur.first; } } return ans; } int main() { ios::sync_with_stdio(false); cin >> n; for (auto i = 0; i < n; ++i) { cin >> p[i].first >> p[i].second; } if (n <= 2) { cout << n << endl; return 0; } cout << max(fromLeft(), fromRight()) << endl; }
#include <bits/stdc++.h> using namespace std; int Max(int a, int b, int c) { cout << a << " " << b << " " << c << endl; return max(a, max(b, c)); } int main() { int n; cin >> n; int x[n], h[n]; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; int ans = 1, pos = x[0]; for (int i = 1; i < n - 1; i++) { if (x[i] - h[i] > pos) { ans++; pos = x[i]; continue; } if (x[i] + h[i] < x[i + 1]) { ans++; pos = x[i] + h[i]; continue; } pos = x[i]; } if (n >= 2) ans++; cout << ans; }
#include <bits/stdc++.h> using namespace std; int n, m[100001], ans; pair<int, int> t[100001]; int main() { cin >> n; m[0] = -2e9; t[n + 1].first = 2e9 + 1; for (int i = 1; i <= n; i++) { cin >> t[i].first >> t[i].second; } for (int i = 1; i <= n; i++) { if (t[i].first - t[i].second > m[i - 1]) { m[i] = t[i].first; ans++; } else if (t[i].first + t[i].second < t[i + 1].first) { m[i] = t[i].first + t[i].second; ans++; } else { m[i] = t[i].first; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long dp[N][2]; long long x[N], h[N]; const long long INF = 1e18; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> x[i] >> h[i]; x[n + 1] = INF; dp[1][0] = 1; if (x[1] + h[1] < x[2]) dp[1][1] = 1; for (int i = 2; i <= n; ++i) { dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]); dp[i][1] = max(dp[i - 1][1], dp[i - 1][0]); if (x[i] - h[i] > x[i - 1]) dp[i][0]++; else if (x[i] + h[i] < x[i + 1]) { x[i] += h[i]; dp[i][1]++; } } cout << max(dp[n][1], dp[n][0]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int n, i, x[100005], h[100005], ans[10005], c = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x[i] >> h[i]; } c++; ans[0] = x[0]; for (i = 1; i < n - 1; i++) { if (x[i] - h[i] > ans[i - 1]) { ans[i] = x[i]; c++; } else if (x[i] + h[i] < x[i + 1]) { ans[i] = x[i] + h[i]; c++; } else { ans[i] = x[i]; } } if (n > 1) c++; cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long k1, k, n, mas[100000], q, m, a[100000], mas1[100000]; int main() { cin >> n; for (long long i = 0; i < n; i++) cin >> mas[i] >> mas1[i]; if (n == 1) { cout << 1; return 0; } a[0] = mas[0]; for (long long i = 1; i < n; i++) { a[i] = mas[i] - mas[i - 1]; } k = 2; for (long long i = 1; i < n - 1; i++) { if (a[i] > mas1[i]) { k++; a[i] = a[i] - mas1[i]; } else if (a[i + 1] > mas1[i]) { k++; a[i + 1] = a[i + 1] - mas1[i]; } } cout << k; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n]; long long int b[n]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } long long int count = 0; if (n >= 2) { count = 2; } else if (n == 1) { count = 1; } for (int i = 1; i < n - 1; i++) { if (a[i] - b[i] > a[i - 1]) { count++; } else if (a[i] + b[i] < a[i + 1]) { count++; a[i] = a[i] + b[i]; } } cout << count << "\n"; }
#include <bits/stdc++.h> using namespace std; const long long dx[] = {1, 0, -1, 0}; const long long dy[] = {0, 1, 0, -1}; int ans; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<long long, long long> > v; for (int i = 0; i < n; i++) { long long temp1, temp2; cin >> temp1 >> temp2; v.push_back({temp1, temp2}); } if (n == 1) { cout << 1; return 0; } ans = 2; for (int i = 1; i < n - 1; i++) { if (v[i].first - v[i].second > v[i - 1].first) { ans++; } else if (v[i].first + v[i].second < v[i + 1].first) { ans++; v[i].first = v[i].first + v[i].second; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { long long n; cin >> n; long long x[n], h[n]; for (long long i = 0; i < n; i++) { cin >> x[i] >> h[i]; } long long ans = 0; long long xl = -9999999999; for (long long i = 0; i < n - 1; i++) { if (x[i] - h[i] > xl) { xl = x[i]; ans++; } else if (x[i] + h[i] < x[i + 1]) { xl = x[i] + h[i]; ans++; } if (xl < x[i]) xl = x[i]; } cout << ans + 1; }
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; for (int x1 = -(1 << 30), h1 = 0, x, h; cin >> x >> h; ++c, x1 = x, h1 = h) { if (x1 + h1 >= x) --c, h1 = 0; if (x - h > x1 + h1) h = 0; } cout << c << "\n"; }
#include <bits/stdc++.h> using namespace std; int a[100000][2]; int main() { int n, count = 1, val; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } for (int i = 1; i < n - 1; i++) { val = a[i][0] - a[i - 1][0]; if (val > a[i][1]) { count++; continue; } val = a[i + 1][0] - a[i][0]; if (val > a[i][1]) { count++; a[i][0] += a[i][1]; } } if (n > 1) count++; cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> H, X; int n; long long DP[100005][2]; long long solve(int i, bool F) { long long &ret = DP[i][F]; if (ret != -1) return ret; if (i == n - 1) return 0; long long F2 = 0, choice1 = 0, choice2 = 0, choice3 = 0, choice4 = 0; if (((X[i] - X[i - 1] - 1) >= H[i]) && F == true) choice1 += solve(i + 1, true) + 1, F2 = 1; if ((X[i + 1] - X[i] - 1) >= H[i]) choice2 += solve(i + 1, false) + 1, F2 = 1; if (X[i] - H[i] > X[i - 1] + H[i - 1]) choice4 += solve(i + 1, true) + 1, F2 = 1; if (F2 == 0) choice3 += solve(i + 1, true); ret = max(choice1, max(choice2, max(choice3, choice4))); return ret; } int main() { memset(DP, -1, sizeof DP); scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); X.push_back(a); H.push_back(b); } if (X.size() > 1) printf("%I64d", solve(1, true) + 2); else printf("1"); }
#include <bits/stdc++.h> using namespace std; template <class T> T scan() { T t; cin >> t; return t; } int dr[] = {0, -1, 1, 0, -1, 1, -1, 1}; int dc[] = {-1, 0, 0, 1, 1, -1, -1, 1}; int main() { int n; cin >> n; vector<pair<int, pair<int, int> > > arr; arr.resize(n); for (int i = 0; i < n; ++i) { int x, h; cin >> x >> h; arr[i] = make_pair(x, make_pair(x - h, x + h)); } int cavab = 1; for (int i = 1; i < n; ++i) { if (arr[i].second.first > arr[i - 1].first) { ++cavab; } else if (i + 1 < n && arr[i].second.second < arr[i + 1].first) { ++cavab; arr[i].first = arr[i].second.second; } else if (i + 1 == n) { ++cavab; } } cout << cavab << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; int x[N], h[N]; void jebaj() { int n; cin >> n; for (auto i = (0); i <= ((n)-1); ++i) { cin >> x[i] >> h[i]; } if (n == 1) { cout << "1\n"; return; } int res = 2; for (auto i = (1); i <= (n - 2); ++i) { if (x[i] - h[i] > x[i - 1]) { res++; } else { if (x[i] + h[i] < x[i + 1]) { res++; x[i] += h[i]; } } } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(0); int t = 1; for (auto i = (0); i <= ((t)-1); ++i) { jebaj(); } }
#include <bits/stdc++.h> using namespace std; void serotonin() {} int32_t main() { serotonin(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long a; cin >> a; long long tree[a]; long long height[a]; for (long long i = 0; i < a; i++) cin >> tree[i] >> height[i]; long long ans = 2; for (long long i = 1; i < a - 1; i++) { if (tree[i] - tree[i - 1] > height[i]) ans++; else if (tree[i + 1] - tree[i] > height[i]) { tree[i] += height[i]; ans++; } } if (a == 1) ans = 1; cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 24; const int mod = 1e9 + 7; int n, m; int main() { int t, q; cin >> n; vector<vector<int> > a(n, vector<int>(2)); for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; int ans = 0; int last_x = a[0][0] - a[0][1]; for (int i = 0; i < n; i++) { int x = a[i][0], h = a[i][1]; if (i == 0) { ans++; } else { if (x - h > last_x and x - h > a[i - 1][0]) { ans++; last_x = x - h; } else if (i < n - 1 and x + h > last_x and x + h < a[i + 1][0]) { ans++; last_x = x + h; } else if (i == n - 1) { ans++; } } } cout << ans << "\n"; ; }
#include <bits/stdc++.h> using namespace std; double const PI = 3.141592653; const int OO = 1000000000 + 9; void fast() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int main() { fast(); int n; cin >> n; vector<pair<int, int>> v(n); for (auto& i : v) { cin >> i.first >> i.second; } int mx = 0; for (int i = 1; i < n - 1; i++) { if (v[i].first - v[i].second > v[i - 1].first) { mx++; } else if (v[i].first + v[i].second < v[i + 1].first) { mx++, v[i].first += v[i].second; } } cout << (n == 1 ? 1 : mx + 2); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 6, M = 1e5 + 5; int OO = 2e9 + 2; int a, b, n, t, k, d, m, x, y, c, z, c2 = 1; string s, s2; long long A[100005]; vector<pair<int, int> > v; vector<pair<int, int> > v2; int mem[100005][6]; int solve(int c, int ch) { if (c >= n - 1) { return 0; } int &ret = mem[c][ch]; if (ret != -1) return ret; ret = 0; if (v[c].first + v[c].second < v[c + 1].first && (v[c].first + v[c].second < A[c + 1] || A[c + 1] == OO)) { A[c] = v[c].first + v[c].second; ret = max(ret, solve(c + 1, 1) + 1); } if (v[c].first - v[c].second > v[c - 1].first && (v[c].first - v[c].second > A[c - 1] || A[c - 1] == OO)) { A[c] = v[c].first - v[c].second; ret = max(ret, solve(c + 1, 2) + 1); } ret = max(ret, solve(c + 1, 3)); return ret; } int main() { cin >> n; memset(mem, -1, sizeof mem); fill(A, A + n + 2, OO); for (int i = 0; i < n; i++) { cin >> a >> b; v.push_back({a, b}); } cout << solve(1, 4) + (n > 1 ? 2 : 1); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct node { int x, h; } p[maxn]; bool operator<(const node &a, const node &b) { return a.x < b.x; } int n; int f[maxn][3]; int main() { cin >> n; if (n == 1) { cout << 1 << endl; return 0; } for (int i = 0; i < n; i++) { scanf("%d %d", &p[i].x, &p[i].h); } sort(p, p + n); memset(f, 0, sizeof(f)); f[0][0] = 1; f[0][1] = 0; if (p[0].x + p[0].h < p[1].x) f[0][2] = 1; else f[0][2] = 1; for (int i = 1; i < n; i++) { f[i][1] = max(f[i - 1][0], max(f[i - 1][1], f[i - 1][2])); if (i == n - 1 || p[i].x + p[i].h < p[i + 1].x) { f[i][2] = max(f[i - 1][0], max(f[i - 1][1], f[i - 1][2])) + 1; } if (p[i].x - p[i].h > p[i - 1].x) { f[i][0] = max(f[i - 1][0], f[i - 1][1]); if (p[i - 1].x + p[i - 1].h < p[i].x - p[i].h) f[i][0] = max(f[i][0], f[i - 1][2]); f[i][0]++; } } cout << max(f[n - 1][0], max(f[n - 1][1], f[n - 1][2])) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long a[100005][2]; int dp[100005][3]; enum direction { n, l, r, }; int main() { int N; cin >> N; for (size_t i = 1; i <= N; i++) { cin >> a[i][0] >> a[i][1]; dp[i][n] = dp[i][l] = dp[i][r] = 0; } a[0][0] = -1e18; a[0][1] = 0; dp[0][l] = dp[0][r] = dp[0][n] = 0; a[N + 1][0] = 1e18; a[N + 1][1] = 0; for (size_t i = 0; i <= N; i++) { if (a[i + 1][0] - a[i][0] > a[i + 1][1] + a[i][1]) { dp[i + 1][l] = 1 + max(max(dp[i][l], dp[i][r]), dp[i][n]); dp[i + 1][n] = max(max(dp[i][l], dp[i][r]), dp[i][n]); } else if (a[i + 1][0] - a[i][0] > a[i + 1][1]) { dp[i + 1][l] = 1 + max(dp[i][l], dp[i][n]); dp[i + 1][n] = max(dp[i][l], max(dp[i][n], dp[i][r])); } if (a[i + 2][0] - a[i + 1][0] > a[i + 2][1] + a[i + 1][1]) { dp[i + 1][r] = 1 + max(max(dp[i][l], dp[i][r]), dp[i][n]); dp[i + 1][n] = max(max(dp[i][l], dp[i][r]), dp[i][n]); } else if (a[i + 2][0] - a[i + 1][0] > a[i + 1][1]) { dp[i + 1][r] = 1 + max(dp[i][r], max(dp[i][n], dp[i][l])); dp[i + 1][n] = max(max(dp[i][n], dp[i][r]), dp[i][l]); } if (!(a[i + 2][0] - a[i + 1][0] > a[i + 1][1]) && !(a[i + 1][0] - a[i][0] > a[i + 1][1])) { dp[i + 1][n] = max(max(dp[i][l], dp[i][r]), dp[i][n]); } } cout << max(max(dp[N][1], dp[N][0]), dp[N][2]); }
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, i = 0; cin >> n; int x[n + 1], h[n + 1], dp[n + 1][3]; for (i = 1; i <= n; i++) { cin >> x[i] >> h[i]; } x[0] = -2000000000; h[0] = 0; dp[0][0] = dp[0][1] = dp[0][2] = 0; for (i = 1; i <= n; i++) { dp[i][0] = 0; if (x[i] - h[i] > x[i - 1]) { dp[i][0] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1); } if (x[i] - h[i] > x[i - 1] + h[i - 1]) { dp[i][0] = max(dp[i][0], dp[i - 1][2] + 1); } dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]); if (x[i] > x[i - 1] + h[i - 1]) { dp[i][1] = max(dp[i][1], dp[i - 1][2]); } dp[i][2] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1); if (x[i] > x[i - 1] + h[i - 1]) { dp[i][2] = max(dp[i][2], dp[i - 1][2] + 1); } } cout << max(max(dp[n][0], dp[n][1]), dp[n][2]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<long long, long long>> tree(n); for (int i = 0; i < n; ++i) cin >> tree[i].first >> tree[i].second; int cuts = 1; for (int i = 1; i < n; ++i) { if (tree[i].first - tree[i].second > tree[i - 1].first) ++cuts; else { if (i == n - 1 || tree[i].first + tree[i].second < tree[i + 1].first) { tree[i].first += tree[i].second; ++cuts; } } } cout << cuts; return 0; }
#include <bits/stdc++.h> const long long int mod = 1000000007; const long long int AM = 2e6 + 5; using namespace std; long long int powm(long long int a, long long int b, long long int n) { long long int x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % n; } y = (y * y) % n; b /= 2; } return x % n; } long long int pow(long long int x, long long int y) { long long int res = 1; while (y > 0) { if (y & 1) res = ((res) * (x)); y = y >> 1; x = ((x) * (x)); } return res; } long long int fact(long long int n) { long long int ans = 1; for (long long int i = 1; i <= n; i++) ans *= i; return ans; } long long int nCr(long long int n, long long int r) { if (r > n - r) r = n - r; long long int ans = 1, i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } bool isPrime(long long int n) { if (n <= 1) return false; for (long long int i = 2; i < n; i++) if (n % i == 0) return false; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int n; cin >> n; long long int a[n + 1], h[n + 1], c[n + 1]; a[0] = -9999999999; h[0] = 0; for (long long int i = 1; i <= n; i++) { cin >> a[i]; cin >> h[i]; } for (long long int i = 1; i <= n; i++) c[i] = a[i - 1]; long long int ans = 1; for (long long int i = 1; i < n; i++) { if (a[i] - c[i] > h[i]) ans++; else if (a[i + 1] - a[i] > h[i]) { ans++; c[i + 1] = c[i + 1] + h[i]; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int n) { if (n == 0) return 1; else if (n == 1) return x; else if (n % 2 == 0) return (power(x, n / 2) % 1000000007 * power(x, n / 2) % 1000000007) % 1000000007; else return (x % 1000000007 * ((power(x, (n - 1) / 2) % 1000000007 * power(x, (n - 1) / 2) % 1000000007) % 1000000007) % 1000000007) % 1000000007; } long long int isprime(long long int n) { long long int i; for (i = 2; i <= (long long int)sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } void multiply(long long int x[3][3], long long int arr[3][3]) { long long int i, j, k; long long int y[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; for (k = 0; k < 3; k++) { for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) y[k][i] = (y[k][i] % 1000000007 + ((x[k][j] % 1000000007 * arr[j][i] % 1000000007) % 1000000007) % 1000000007) % 1000000007; } } for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { x[i][j] = y[i][j]; } } } void power(long long int arr[3][3], long long int n) { long long int i, j; if (n == 1) return; else if (n % 2 == 0) { power(arr, n / 2); multiply(arr, arr); } else { long long int x[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) x[i][j] = arr[i][j]; } power(arr, n / 2); multiply(arr, arr); multiply(arr, x); } } long long int matrixexpo(long long int a, long long int b, long long int c, long long int n) { long long int i, j; long long int arr[3][3] = {{a, b, c}, {1, 0, 0}, {0, 1, 0}}; power(arr, n - 2); return (((((arr[0][0] % 1000000007 * 4 % 1000000007) % 1000000007) % 1000000007 + ((arr[0][1] % 1000000007 * 2 % 1000000007) % 1000000007) % 1000000007) % 1000000007) % 1000000007 + ((arr[0][2] % 1000000007 * 1 % 1000000007) % 1000000007) % 1000000007) % 1000000007; } int main() { long long int n, i, j, c = 2; cin >> n; long long int arr[n][2]; for (i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1]; if (n == 1) cout << 1 << '\n'; else { for (i = 1; i < n - 1; i++) { if (arr[i][0] - arr[i][1] > arr[i - 1][0]) c++; else if (arr[i][1] + arr[i][0] < arr[i + 1][0]) { c++; arr[i][0] = arr[i][1] + arr[i][0]; } } cout << c << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int x[n + 5], h[n + 5], i; for (i = 0; i < n; ++i) cin >> x[i] >> h[i]; int count = min(n, 2); long long int prev = 0; for (i = 1; i < n - 1; ++i) { if (x[i] - x[i - 1] > h[i] + prev) { ++count; prev = 0; } else { if (x[i + 1] - x[i] > h[i]) { ++count; prev = h[i]; } else prev = 0; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long fun(vector<pair<long long, long long> > &v) { long long i, j, k, n = v.size(); if (n == 1) return 1; long long ans = 2; long long ptr = v[0].first; for (i = 1; i < n - 1; i++) { if (v[i].first - v[i].second > v[i - 1].first) { ptr = v[i].first; ans++; } else if (v[i].first + v[i].second < v[i + 1].first) { ptr = v[i].first + v[i].second; v[i].first += v[i].second; ans++; } } return ans; } void input(vector<pair<long long, long long> > &v) { long long i, j, n = v.size(); for (i = 0; i < n; i++) cin >> v[i].first >> v[i].second; } int main() { int t; t = 1; while (t--) { long long i, j, k, n; cin >> n; vector<pair<long long, long long> > vp(n); input(vp); sort(vp.begin(), vp.end()); cout << fun(vp) << endl; } return 0; }