Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma comment(linker, "/STACK:16777216")
- #include <fstream>
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <complex>
- #include <math.h>
- #include <cmath>
- #include <cstring>
- #include <cstdio>
- #include <cassert>
- #include <set>
- #include <vector>
- #include <map>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <algorithm>
- #include <bitset>
- #include <list>
- using namespace std;
- #define x first
- #define y second
- #define pb push_back
- #define mp make_pair
- #define all(a) (a).begin(), (a).end()
- #define rall(a) (a).rbegin(), (a).rend()
- #define sz(a) int((a).size())
- #define sqr(x) ((x)*(x))
- #define forn(i, n) for (int i = 0; i < int(n); i++)
- #define foreach(i, a) for (auto i : a)
- #define NAME "library"
- #define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
- #define Freopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- #define y0 sdkfaslhagaklsldk
- #define y1 aasdfasdfasdf
- #define yn askfhwqriuperikldjk
- #define j1 assdgsdgasghsf
- #define tm sdfjahlfasfh
- #define lr asgasgashqt
- #define free afdshjioeyqtw
- #define next qpowityqwopqw
- #define prev paoueoroill
- typedef unsigned int unt;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef pair < int, int > pii;
- typedef pair < ll, ll > pll;
- const ll MOD = 1e9 + 7;
- const int INF = 1e9 + 1;
- const ll INF64 = 2e18;
- const ll T = 23525;
- const ll MD = 1623623452;
- const int N = 300011;
- const int M = 20010;
- int n, s[N], f[N], c[N];
- vector < pii > a;
- set < pii > s1, s2;
- void er() {
- cout << "NO";
- exit(0);
- }
- int main() {
- FREOPEN;
- ios::sync_with_stdio(0);
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> s[i] >> f[i] >> c[i];
- a.pb(mp(s[i], i));
- a.pb(mp(s[i] + c[i], -1));
- a.pb(mp(f[i], -1));
- }
- sort(all(a));
- forn(i, sz(a)) {
- int j = i;
- while (j < sz(a) && a[i].x == a[j].x) {
- if (a[j].y > 0)
- s1.insert(mp(a[j].x + c[a[j].y], a[j].y));
- j++;
- }
- i = j - 1;
- while (!s1.empty() && s1.begin()->x == a[i].x) {
- int v = s1.begin()->y;
- s1.erase(s1.begin());
- s2.insert(mp(f[v], v));
- }
- int dd = a[i].x;
- while (!s2.empty() && (i == sz(a) - 1 || a[i + 1].x > dd)) {
- if (s2.begin()->x < dd)
- er();
- s2.erase(s2.begin());
- dd++;
- }
- }
- cout << "YES";
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment