text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
pair<int, int> d[1000];
for (int i = 0; i < n; i++) cin >> d[i].first >> d[i].second;
sort(d, d + n);
for (int i = 0; i < n; i++) {
if (s > d[i].first)
s += d[i].second;
else
s = 0;
}
if (s == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
const long double pi = 3.1415926535898;
int main() {
int s, n;
cin >> s >> n;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if (a[i].first >= s) {
cout << "NO";
return 0;
}
s += a[i].second;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
pair<int, int> p[y];
for (int i = 0; i < y; i++) cin >> p[i].first >> p[i].second;
sort(p, p + y);
for (int i = 0; i < y; i++) {
if (p[i].first < x)
x += p[i].second;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, i;
cin >> s >> n;
int a[n], b[n];
for (i = 0; i < n; i++) cin >> a[i] >> b[i];
vector<pair<int, int>> v;
for (i = 0; i < n; i++) v.push_back({a[i], b[i]});
sort(v.begin(), v.end());
int f = 0;
for (i = 0; i < n; i++) {
if (s > v[i].first)
s += v[i].second;
else {
f = 1;
break;
}
}
if (f)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[1000], b[1000], s, j, i, n;
cin >> s >> n;
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < n - 1; i++)
for (j = i + 1; j < n; j++)
if (a[i] > a[j]) {
int tg = a[i];
a[i] = a[j];
a[j] = tg;
tg = b[i];
b[i] = b[j];
b[j] = tg;
}
for (i = 0; i < n; i++)
if (s > a[i])
s += b[i];
else {
cout << "NO";
return 0;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> s >> n;
int x, y;
int flag = 0;
vector<pair<int, int> > v;
for (int i = 0; i < n; i++) {
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (s > v[i].first) {
s = s + v[i].second;
} else {
flag = 1;
}
}
if (flag == 1)
cout << "NO"
<< "\n";
else
cout << "YES"
<< "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
while (scanf("%d%d", &s, &n) == 2) {
vector<int> strength, bonus;
int i, j, l = n, ll = 0;
while (n--) {
int x, y;
scanf("%d%d", &x, &y);
strength.push_back(x);
bonus.push_back(y);
}
for (i = 0; i < l; i++) {
for (j = 0; j < l; j++) {
if (s > strength.at(j) && strength.at(j) != 0) {
s += bonus.at(j);
strength.at(j) = 0;
ll++;
}
}
}
if (strength.size() == ll)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int a[1001][1001];
int b[1001];
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
b[i] = a[i][0];
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[j][0] == b[i]) {
if (s <= a[j][0]) {
cout << "NO";
return 0;
} else {
s = s + a[j][1];
a[j][0] = -1;
break;
}
}
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int s, n, i, t, j, w;
scanf("%d%d", &s, &n);
int x[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) scanf("%d", &x[i][j]);
}
for (i = 1; i < n; i++) {
for (j = 0; j < n - i; j++) {
if (x[j][0] >= x[j + 1][0]) {
t = x[j][0];
w = x[j][1];
x[j][0] = x[j + 1][0];
x[j][1] = x[j + 1][1];
x[j + 1][0] = t;
x[j + 1][1] = w;
}
}
}
t = 0;
for (i = 0; i < n; i++) {
if (s > x[i][0]) {
s += x[i][1];
t++;
}
}
if (t == n)
printf("YES");
else
printf("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y, i, cnt = 0, a[1000], b[1000], j;
scanf("%d%d", &s, &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
a[i] = x;
b[i] = y;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
swap(b[j], b[j + 1]);
}
}
}
for (i = 0; i < n; i++) {
if (s > a[i]) {
cnt++;
}
s += b[i];
}
if (cnt == n) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool lucky(long long n) {
set<long long> s;
while (n > 0) {
s.insert(n % 10);
n /= 10;
}
for (long long i = 0; i <= 9; i++) {
if (i == 4 || i == 7)
continue;
else if (s.count(i) > 0)
return false;
}
s.clear();
return true;
}
int main() {
long long s, n;
cin >> s >> n;
priority_queue<pair<long long, long long>> p;
for (long long i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
p.push({-1 * a, b});
}
long long power = s;
bool no = false;
for (long long i = 0; i < n; i++) {
auto pp = p.top();
p.pop();
if (power <= -1 * pp.first) {
no = true;
break;
} else {
power += pp.second;
}
}
if (no)
cout << "NO\n";
else
cout << "YES\n";
}
|
#include <bits/stdc++.h>
using namespace std;
vector<bool> is_prime;
vector<long long> primes;
void removeZeroes(string &s) {
string ans;
for (long long i = 0; i < s.length(); i++) {
if (s[i] != '0') {
ans += s[i];
}
}
s = ans;
}
signed main() {
long long s;
cin >> s;
long long n;
cin >> n;
vector<pair<long long, long long>> v;
for (long long i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
for (long long i = 0; i < v.size(); i++) {
if (s > v[i].first) {
s += v[i].second;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int x[n], y[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if ((x[i] > x[j])) {
int temp = x[i];
x[i] = x[j];
x[j] = temp;
int temp2 = y[i];
y[i] = y[j];
y[j] = temp2;
}
}
}
int count = 0;
for (int i = 0; i < n; i++) {
if (s > x[i]) {
s += y[i];
count++;
}
}
if (count == n) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, i;
cin >> s >> n;
vector<int> v1;
vector<int> v2;
int a, b;
for (i = 0; i < n; i++) {
cin >> a >> b;
v1.push_back(a);
v2.push_back(b);
}
vector<pair<int, int> > v3;
for (i = 0; i < n; i++) {
v3.push_back(make_pair(v1[i], i));
}
sort(v3.begin(), v3.end());
for (i = 0; i < n; i++) {
if (s > v3[i].first) {
s = s + v2[v3[i].second];
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, a[10000] = {0}, m = -1, y, i;
cin >> s >> n;
int c = n;
while (n--) {
cin >> i >> y;
a[i] += y;
m = max(m, i);
}
for (int i = 0; i < 10000; i++) {
if (s > i) {
s += a[i];
}
}
s > m ? cout << "YES" : cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int x, c, i, j, s, n, array, num;
pair<int, int> a[1000];
while (cin >> s >> n) {
c = 1;
for (i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
for (i = 0; i < n; i++) {
if (s <= a[i].first) {
c = 0;
break;
} else {
s = s + a[i].second;
}
}
if (c == 0)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct game {
int a, b;
};
bool mycmp(game a, game b) { return a.a < b.a; }
int main() {
int s, n, k, l, i;
scanf("%d %d", &s, &n);
game d[n];
for (l = 0; l < n; l++) scanf("%d %d", &d[l].a, &d[l].b);
sort(d, d + n, mycmp);
for (l = 0; l < n; l++) {
if (d[l].a >= s) {
puts("NO");
return 0;
}
s += d[l].b;
}
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
bool l = 0;
vector<pair<int, int> > v;
cin >> s >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (s > v[i].first) {
s += v[i].second;
} else {
cout << "NO";
l = 1;
break;
}
}
if (l == 0) {
cout << "YES";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int x[n], y[n], p[n];
for (int i = 0; i < n; i++) {
cin >> x[i];
cin >> y[i];
p[i] = x[i];
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
int k = p[i];
if (k == 100000) {
break;
}
for (int j = 0; j < n; j++) {
if (x[j] == k) {
if (k < s) {
s = s + y[j];
} else {
cout << "NO" << endl;
exit(0);
}
x[j] = 100000;
}
}
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int s, n;
cin >> s >> n;
vector<pair<int, int> > ve;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
ve.push_back(make_pair(a, b));
}
sort(ve.begin(), ve.end());
int flag = 1;
for (int i = 0; i < n; i++) {
if (s <= ve[i].first) {
flag = 0;
break;
} else {
s += ve[i].second;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
long long t = 1;
while (t--) {
long long n, k;
cin >> k >> n;
vector<pair<long long, long long> > v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
sort(v.begin(), v.end());
for (long long i = 0; i < n; i++) {
if (k <= v[i].first) {
cout << "NO\n";
return 0;
} else {
k += v[i].second;
}
}
cout << "YES\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int x[n], y[n];
int i, j, flag;
for (i = 0; i < n; i++) cin >> x[i] >> y[i];
for (i = 0; i < n; i++) {
for (j = 0; j < n - i - 1; j++) {
if (x[j] > x[j + 1]) {
flag = x[j];
x[j] = x[j + 1];
x[j + 1] = flag;
flag = y[j];
y[j] = y[j + 1];
y[j + 1] = flag;
}
}
}
flag = 0;
for (i = 0; i < n; i++) {
if (s > x[i])
s += y[i];
else {
flag = -1;
break;
}
}
if (flag == -1)
cout << "NO";
else
cout << "YES";
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortByFirst(pair<int, int> i, pair<int, int> j) {
return i.first < j.first;
}
int main() {
int n, x, y;
long long int s;
bool canPass = true;
vector<pair<int, int>> inp;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
inp.push_back(make_pair(x, y));
}
sort(inp.begin(), inp.end(), sortByFirst);
for (int i = 0; i < n && canPass; i++) {
x = inp[i].first;
y = inp[i].second;
if (x >= s)
canPass = false;
else
s += y;
}
if (canPass)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
long long f = 1;
for (long long i = 2; i <= n; i++) f *= i;
return f;
}
long long ncr(long long n, long long r) {
return fact(n) / (fact(r) * fact(n - r));
}
long long isPrime(long long n) {
if (n <= 1) return 0;
if (n <= 3) return 1;
if (n % 2 == 0 || n % 3 == 0) return 0;
for (long long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
srand(time(NULL));
long long n, p;
cin >> p >> n;
vector<pair<long long, long long> > v;
for (long long i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
v.push_back(make_pair(a, b));
}
sort(v.begin(), v.end());
long long c = 0;
for (long long i = 0; i < n; i++) {
if (v[i].first >= p) {
c++;
}
p += v[i].second;
}
if (c > 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
int n, m, cnt = 0;
cin >> n >> m;
pair<int, int> pr[m];
for (int i = 0; i < m; i++) {
cin >> pr[i].first >> pr[i].second;
}
sort(pr, pr + m);
for (int i = 0; i < m; i++) {
if (n > pr[i].first)
n += pr[i].second;
else
return cout << "NO", 0;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
string solve(int f, vector<pair<int, int> >& xs) {
int N = xs.size();
sort(xs.begin(), xs.end());
for (int i = 0; i < N; i++) {
if (f > xs[i].first) {
f += xs[i].second;
} else {
return "NO";
}
}
return "YES";
}
int main() {
int N, S;
cin >> S >> N;
vector<pair<int, int> > xs(N);
for (int i = 0; i < N; i++) cin >> xs[i].first >> xs[i].second;
auto ans = solve(S, xs);
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, i, j, c = 0;
cin >> s >> n;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
swap(a[i], a[j]);
swap(b[i], b[j]);
}
}
for (i = 0; i < n && c == 0; i++) {
if (s > a[i])
s = s + b[i];
else {
c = 1;
}
}
if (c == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmpfunc(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first < b.first);
}
int main() {
long long s, n, i;
cin >> s >> n;
pair<long long, long long> drag[n];
for (i = 0; i < n; i++) cin >> drag[i].first >> drag[i].second;
sort(drag, drag + n, cmpfunc);
for (i = 0; i < n; i++) {
if (drag[i].first < s) {
s += drag[i].second;
} else {
break;
}
}
if (i == n)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int s, n, a, b;
vector<pair<int, int>> v;
int main() {
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
v.push_back(make_pair(a, b));
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (s <= v[i].first) {
cout << "NO";
return 0;
} else {
s += v[i].second;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
bool win = true;
for (int j = 0; j < n; j++) {
if (s <= v[j].first) {
win = false;
break;
} else {
s += v[j].second;
}
}
if (win)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y, m1 = 0, m2;
cin >> n >> m;
pair<int, int> a1[100000];
for (int i = 0; i < m; i++) cin >> a1[i].first >> a1[i].second;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (a1[j].first < a1[m1].first) m1 = j;
}
if (n > a1[m1].first) {
n = n + a1[m1].second;
a1[m1].first = INT_MAX;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long s, n;
cin >> s >> n;
pair<long long, long long> p[n + 5];
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
if (s <= p[i].first) return cout << "NO", 0;
s += p[i].second;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> b, pair<int, int> a) {
return (a.first > b.first || a.first == b.first && a.second < b.second);
}
int main() {
int s, n, i, b, c;
bool flag = true;
scanf("%d%d", &s, &n);
vector<pair<int, int> > a;
for (i = 0; i < n; i++) {
scanf("%d%d", &b, &c);
a.push_back(make_pair(b, c));
}
sort(a.begin(), a.end(), cmp);
for (i = 0; i < n; i++) {
b = a[i].first;
c = a[i].second;
if (s > b)
s += c;
else {
flag = false;
break;
}
}
if (flag)
printf("YES");
else
printf("NO");
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int s, n, i, j, mid1, mid2;
scanf("%d %d", &s, &n);
int a[n + 1][3];
for (i = 1; i < n + 1; i++) scanf("%d %d", &a[i][1], &a[i][2]);
for (i = 1; i < n; i++) {
for (j = 1; j < n + 1 - i; j++) {
if (a[j][1] > a[j + 1][1]) {
mid1 = a[j][1];
a[j][1] = a[j + 1][1];
a[j + 1][1] = mid1;
mid2 = a[j][2];
a[j][2] = a[j + 1][2];
a[j + 1][2] = mid2;
}
}
}
for (i = 1; i < n + 1; i++) {
if (s > a[i][1]) {
s += a[i][2];
} else {
break;
}
}
if (i >= n + 1)
printf("YES");
else
printf("NO");
}
|
#include <bits/stdc++.h>
int x[10010];
int y[10010];
void _qsort(int x[], int y[], int l, int h) {
int key, ll = l, hh = h, q, temp, k2;
if (l >= h) return;
key = x[ll];
k2 = y[ll];
while (ll < hh) {
while (ll < hh && key <= x[hh]) hh--;
if (ll < hh) {
x[ll] = x[hh];
y[ll] = y[hh];
ll++;
}
while (ll < hh && x[ll] <= key) ll++;
if (ll < hh) {
x[hh] = x[ll];
y[hh] = y[ll];
hh--;
}
}
x[ll] = key;
y[ll] = k2;
_qsort(x, y, l, ll - 1);
_qsort(x, y, ll + 1, h);
}
int main() {
int a, b, c, i, j, k, s, n;
scanf("%d%d", &s, &n);
j = 0;
for (i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
}
_qsort(x, y, 0, n - 1);
for (i = 0; i < n; i++) {
if (s > x[i]) {
s += y[i];
} else {
j = 1;
break;
}
}
if (j == 1)
printf("NO\n");
else
printf("YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct my {
int a, b;
};
bool com(my ob, my ob1) {
if (ob.a < ob1.a)
return true;
else
return false;
}
int main() {
long long int n, n1;
int a, b;
int f = 1;
cin >> n >> n1;
my ob[n1];
for (int i = 0; i < n1; i++) {
cin >> ob[i].a >> ob[i].b;
}
sort(ob, ob + n1, com);
for (int i = 0; i < n1; i++) {
if (n > ob[i].a) {
n = n + ob[i].b;
} else {
f = 0;
break;
}
}
if (f == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void pairsort(int a[], int b[], int x) {
pair<int, int> pairt[x];
for (int i = 0; i < x; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + x);
for (int i = 0; i < x; i++) {
a[i] = pairt[i].first;
b[i] = pairt[i].second;
}
}
int main() {
int n, m, arr[100000], brr[100000];
cin >> n >> m;
int strength = n, cnt = 0;
for (int i = 0; i < m; i++) {
cin >> arr[i] >> brr[i];
}
pairsort(arr, brr, m);
if (arr[0] >= n) {
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < m; i++) {
strength += brr[i];
if (strength > arr[i + 1]) {
cnt++;
}
}
if (cnt == m)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
vector<pair<int, int>> d;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
d.push_back(make_pair(a, b));
}
sort(d.begin(), d.end());
for (int i = 0; i < d.size(); i++) {
if (s <= d[i].first) {
cout << "NO" << endl;
return 0;
}
s += d[i].second;
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<int, int> p[10000];
int s, n, x, y;
bool f = 0;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
p[i] = make_pair(x, y);
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
if (s > p[i].first)
s += p[i].second;
else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int array[n][2];
int array1[n][2];
int result = 0;
for (int i = (0); i < (n); i++) {
for (int j = (0); j < (2); j++) {
cin >> array[i][j];
}
}
for (int k = (0); k < (n); k++) {
for (int i = (0); i < (n); i++) {
if (s > array[i][0] && array[i][0] != 0) {
s = s + array[i][1];
array[i][0] = 0;
array[i][1] = 0;
result = result + 1;
}
}
}
if (result == n)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int p, q;
} a[1009];
bool cmp(node a, node b) {
if (a.p != b.p) return a.p < b.p;
if (a.p == b.p) return a.q > b.q;
}
int main() {
int m, n, i;
scanf("%d%d", &m, &n);
for (i = 1; i <= n; i++) {
scanf("%d%d", &a[i].p, &a[i].q);
}
sort(a + 1, a + 1 + n, cmp);
int sum = m;
for (i = 1; i <= n; i++) {
if (sum > a[i].p)
sum += a[i].q;
else
break;
}
if (i == n + 1)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int bugf;
inline int in() {
scanf("%d", &bugf);
return bugf;
}
const double eps = 1e-7;
int round_(double a) {
if (a < eps)
return (int)(a - 0.5);
else
return (int)(a + 0.5);
}
double dist2(double x1, double y1, double x2, double y2) {
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
int f(double x) {
if (fabs(x) < eps) return 0;
if (x < 0) return -1;
return 1;
}
int main() {
int s = in(), n = in();
long long res = 0;
vector<pair<int, int> > a;
for (int i = 0; i < n; ++i) {
int di = in(), b = in();
pair<int, int> cur;
cur.first = di;
cur.second = b;
a.push_back(cur);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
if (a[j].first != -1 && a[j].first < s) {
a[j].first = -1;
++res;
s += a[j].second;
}
}
if (res == n) {
puts("YES");
} else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> &i, pair<int, int> &j) { return i.first < j.first; }
int main() {
int s, n, a, b;
vector<pair<int, int>> v;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
v.push_back(make_pair(a, b));
}
sort(v.begin(), v.end(), compare);
bool dis = true;
for (int i = 0; i < n; i++) {
if (s > v[i].first) {
s = s + v[i].second;
} else {
dis = false;
cout << "NO";
break;
}
}
if (dis) cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
string str;
long long solve() {
long long s;
cin >> s >> n;
long long x[n], y[n], z[n];
for (long long i = 0; i <= n - 1; ++i) {
cin >> x[i] >> y[i];
z[i] = 0;
}
long long f = 0;
while (1) {
f = 0;
for (long long i = 0; i <= n - 1; ++i) {
if (z[i] == 0 && s > x[i]) {
s += y[i];
z[i] = 1;
f = 1;
}
}
if (f == 0) break;
}
long long t = 0;
for (long long i = 0; i <= n - 1; ++i) {
if (z[i]) t++;
}
if (t == n)
cout << "YES";
else
cout << "NO";
return 0;
}
signed main() {
ios::sync_with_stdio(0);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int MXN = 3e5 + 1;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double PI = acos(-1.0);
int second, n, x[N], y[N];
pair<int, int> p[N];
int main() {
cin >> second >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++) {
if (second > p[i].first) {
second += p[i].second;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL), cerr << "";
int s, n;
cin >> s >> n;
pair<int, int> p[n];
for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
sort(p, p + n);
for (int i = 0; i < n; i++)
if (s <= p[i].first)
return cout << "NO\n", 0;
else
s += p[i].second;
return cout << "YES\n", 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct dragon {
int sila;
int dodatek;
};
bool operator<(dragon A, dragon B) { return A.sila < B.sila; }
int main() {
int s, n;
cin >> s >> n;
vector<dragon> D(n);
for (int i = 0; i < n; i++) {
cin >> D[i].sila >> D[i].dodatek;
}
sort(D.begin(), D.end());
for (int p = 0; p < n; p++) {
if (s > D[p].sila)
s += D[p].dodatek;
else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
int main() {
int s, n, i, j, t, c = 0;
scanf("%d%d", &s, &n);
int a[n], b[n];
for (i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
for (i = 0; i < n; i++) {
for (j = n - 1; j > 0; j--) {
if (a[j - 1] > a[j]) {
t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
t = b[j - 1];
b[j - 1] = b[j];
b[j] = t;
}
}
}
for (i = 0; i < n; i++) {
if (a[i] < s) {
c++;
s += b[i];
}
}
if (c == n)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, i, s;
pair<int, int> p[1001];
int main() {
cin >> s >> n;
for (i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p, p + n);
for (i = 0; i < n; i++) {
if (s > p[i].first)
s = s + p[i].second;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
int a[n][2];
bool b[n][2];
int wrong = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> a[i][j];
b[i][j] = true;
}
}
for (int i = 0; i < n; i++) {
if (s <= a[i][0]) {
b[i][0] = false;
wrong++;
} else
s += a[i][1];
}
if (wrong == 0) {
cout << "YES" << endl;
return 0;
}
do {
int index = wrong;
for (int i = 0; i < n; i++) {
if (b[i][0] == false && s > a[i][0]) {
b[i][0] = true;
s += a[i][1];
wrong--;
}
}
if (index == wrong) {
cout << "NO" << endl;
return 0;
}
} while (wrong != 0);
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int r = exgcd(b, a % b, x, y);
int t = y;
y = x - a / b * y;
x = t;
return r;
}
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
inline int abs(int a) { return a > 0 ? a : -a; }
bool leitu(int a, int &x, int b, int &y, int c) {
int s, t;
int GCD = exgcd(a, b, s, t);
if (abs(c) % GCD) return false;
int s0 = (-s) * c / GCD;
int t0 = t * c / GCD;
int B = b / GCD;
int A = a / GCD;
if (s0 >= 0 && t0 >= 0) {
while (s0 - B >= 0 && t0 - A >= 0) {
s0 -= B;
t0 -= A;
}
} else {
while (!(s0 >= 0 && t0 >= 0)) {
s0 += B;
t0 += A;
}
}
x = s0;
y = t0;
return true;
}
int DAC_array_gcd(int a[], int s, int e) {
if (s == e) return a[s];
int mid = (s + e) / 2;
int l = DAC_array_gcd(a, s, mid);
int r = DAC_array_gcd(a, mid + 1, e);
return gcd(l, r);
}
const int maxn = (int)1e3 + 10;
std::pair<int, int> d[maxn];
int s, n;
void xQsort(int low, int high) {
if (low >= high) return;
int first = low;
int last = high;
std::pair<int, int> key = d[first];
while (first < last) {
while (first < last && d[last].first >= key.first) last--;
d[first] = d[last];
while (first < last && d[first].first <= key.first) first++;
d[last] = d[first];
}
d[first] = key;
xQsort(low, first - 1);
xQsort(first + 1, high);
}
int xBsearch(int low, int high, int x) {
if (high - low <= 1) {
if (x <= d[low].first)
return -1;
else if (d[high].first < x)
return high;
else
return low;
}
int mid = (low + high) / 2;
if (x <= d[mid].first)
return xBsearch(low, mid - 1, x);
else
return xBsearch(mid, high, x);
}
int main() {
int x, y;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
d[i].first = x;
d[i].second = y;
}
xQsort(0, n - 1);
int l = 0, r;
bool flag = true;
while (l < n) {
r = xBsearch(l, n - 1, s);
if (r == -1) {
flag = false;
break;
}
for (int i = l; i <= r; i++) s += d[i].second;
l = r + 1;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
for (int i = 0; i < n; ++i) {
if (v[i].first < s)
s += v[i].second;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct TARR {
int *m_Arr;
};
int cmpFunc(const void *a, const void *b) {
TARR u = *(TARR *)a;
TARR v = *(TARR *)b;
return (u.m_Arr[0] - v.m_Arr[0]);
}
int main(void) {
int s = 0, n = 0;
cin >> s >> n;
TARR *arr = new TARR[n];
for (int i = 0; i < n; i++) arr[i].m_Arr = new int[2];
for (int i = 0; i < n; i++) cin >> arr[i].m_Arr[0] >> arr[i].m_Arr[1];
qsort(arr, n, sizeof(int *), cmpFunc);
for (int i = 0; i < n; i++) {
if (s <= arr[i].m_Arr[0]) {
cout << "NO" << endl;
return 0;
} else {
s += arr[i].m_Arr[1];
}
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) delete[](arr[i].m_Arr);
delete[] arr;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int strKirito, numDragon;
cin >> strKirito >> numDragon;
int strDragon[numDragon];
int bonus[numDragon];
for (int i = 0; i < numDragon; i++) {
cin >> strDragon[i] >> bonus[i];
}
int temp;
int sorted = 0;
while (sorted == 0) {
sorted = 1;
for (int i = 1; i <= numDragon - 2; i = i + 2) {
if (strDragon[i] > strDragon[i + 1]) {
temp = strDragon[i];
strDragon[i] = strDragon[i + 1];
strDragon[i + 1] = temp;
temp = bonus[i];
bonus[i] = bonus[i + 1];
bonus[i + 1] = temp;
sorted = 0;
}
}
for (int i = 0; i <= numDragon - 2; i = i + 2) {
if (strDragon[i] > strDragon[i + 1]) {
temp = strDragon[i];
strDragon[i] = strDragon[i + 1];
strDragon[i + 1] = temp;
temp = bonus[i];
bonus[i] = bonus[i + 1];
bonus[i + 1] = temp;
sorted = 0;
}
}
}
for (int i = 0; i < numDragon; i++) {
if (strDragon[i] < strKirito) {
strKirito = strKirito + bonus[i];
if (i == numDragon - 1) {
cout << "YES" << endl;
}
}
if (strDragon[i] >= strKirito) {
cout << "NO" << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y;
cin >> s >> n;
vector<pair<int, int> > v;
pair<int, int> p;
for (int i = 0; i < n; i++) {
cin >> x >> y;
p = make_pair(x, y);
v.push_back(p);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (v[i].first < s)
s += v[i].second;
else {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y, i, cnt = 0, a[1000], b[1000], j;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
swap(b[j], b[j + 1]);
}
}
}
for (int i = 0; i < n; i++) {
if (s > a[i]) {
cnt++;
}
s += b[i];
}
if (cnt == n) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y;
bool flag = 0;
multimap<int, int, greater<int>> v;
cin >> s >> n;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
v.insert(pair<int, int>(x, y));
}
for (auto iter = v.rbegin(); iter != v.rend(); ++iter) {
if (s > iter->first) {
s += iter->second;
} else {
flag = 1;
break;
}
}
if (flag == 0) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y;
cin >> s >> n;
vector<pair<int, int>> mp;
for (int i = 0; i < n; i++) {
cin >> x >> y;
mp.push_back({x, y});
}
sort(mp.begin(), mp.end());
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->first >= s) {
cout << "NO"
<< "\n";
return 0;
} else {
s += it->second;
}
}
cout << "YES"
<< "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, n;
cin >> s >> n;
vector<pair<int, int>> v;
int arr1[n];
int arr2[n];
for (int i = 0; i < n; i++) {
cin >> arr1[i] >> arr2[i];
}
for (int i = 0; i < n; i++) {
v.push_back(make_pair(arr1[i], arr2[i]));
}
sort(v.begin(), v.end());
bool res = true;
for (int i = 0; i < n; i++) {
if (s > v[i].first) {
s += v[i].second;
} else {
res = false;
break;
}
}
if (res) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
inline void arin(T* st, T* nd) {
while (st < nd) cin >> *st++;
}
const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
bool cmd(pair<int, int> x, pair<int, int> y) { return (x.first < y.first); }
int main() {
vector<pair<int, int> > inp;
int n, s, a, b;
cin >> s >> n;
for (int i = 0; i < (int)(n); i++) {
cin >> a >> b;
inp.push_back({a, b});
}
sort(inp.begin(), inp.end(), cmd);
for (int i = 0; i < (int)(n); i++) {
if (s > inp[i].first) {
s += inp[i].second;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortp(const pair<int, int> a, const pair<int, int> b) {
if (a.first > b.first)
return 0;
else if (a.first < b.first)
return 1;
else
return a.second > b.second;
}
int main() {
int n, m;
cin >> n >> m;
pair<int, int> b;
vector<pair<int, int>> a;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
b.first = x;
b.second = y;
a.push_back(b);
}
sort(a.begin(), a.end(), sortp);
int flag = 0;
for (int i = 0; i < m; i++) {
if (n <= a[i].first) {
cout << "NO" << endl;
flag = 1;
break;
} else {
n += a[i].second;
}
}
if (flag == 0) {
cout << "YES" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, u, i;
cin >> p >> n;
vector<pair<int, int> > a;
for (int k = 1; k <= n; k++) {
cin >> u >> i;
a.push_back(make_pair(u, i));
}
sort(a.begin(), a.end());
for (int k = 0; k < n; k++) {
if (a[k].first >= p) {
cout << "NO";
return 0;
}
p += a[k].second;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int s, n;
pair<int, int> a[100005];
int main() {
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (s > a[i].first) {
s += a[i].second;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct dra {
int x, y;
};
dra p[1010];
bool cmp(const dra &d1, const dra &d2) {
if (d1.x < d2.x)
return true;
else {
if (d1.x == d2.x) {
if (d1.y > d2.y) return true;
}
}
return false;
}
int main() {
int i, n, s, flag[1010];
scanf("%d%d", &s, &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &p[i].x, &p[i].y);
}
sort(p, p + n, cmp);
for (i = 0; i < n; i++) {
if (s <= p[i].x) {
printf("NO");
return 0;
} else
s += p[i].y;
}
printf("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, flag = 0;
int x[1001], y[1001];
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 1; i <= n - 1; i++) {
int j = i;
while (j > 0 && x[j] < x[j - 1]) {
int temp = x[j];
x[j] = x[j - 1];
x[j - 1] = temp;
temp = y[j];
y[j] = y[j - 1];
y[j - 1] = temp;
j--;
}
}
for (int i = 0; i < n; i++) {
if (s <= x[i]) {
flag = 1;
break;
} else
s += y[i];
}
if (flag == 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
bool flag;
using namespace std;
int main() {
vector<pair<long long, long long> > vc;
long long s, n, a, b;
cin >> s >> n;
while (n--) {
cin >> a >> b;
vc.push_back(make_pair(a, b));
}
sort(vc.begin(), vc.end());
for (long long i = 0; i < vc.size(); i++) {
if (vc[i].first >= s) {
cout << "NO\n";
return 0;
}
s += vc[i].second;
}
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, x, y;
cin >> s >> n;
multimap<int, int> dragons;
for (int i = 0; i < n; i++) {
cin >> x >> y;
dragons.insert({x, y});
}
bool flag = true;
for (auto it = dragons.begin(); it != dragons.end(); it++) {
if (it->first < s) {
s += it->second;
} else {
flag = false;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, m, c = 0, bonas[10000], power[10000];
cin >> x >> m;
for (int i = 0; i < m; i++) {
cin >> power[i] >> bonas[i];
}
for (int i = 0; i < m; i++) {
for (int g = 0; g < (m - i - 1); g++) {
if (power[g] > power[g + 1]) {
swap(power[g], power[g + 1]);
swap(bonas[g], bonas[g + 1]);
}
}
}
for (int i = 0; i < m; i++) {
if (x > power[i]) c++;
x += bonas[i];
}
if (c >= m)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int s, n;
cin >> s >> n;
int a[n][2];
int num;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> a[i][j];
}
}
bool flag = true;
for (int x = 0; x < n; x++) {
int mini = a[0][0];
int index = 0;
for (int i = 0; i < n; i++) {
if (mini > a[i][0]) {
mini = a[i][0];
index = i;
}
}
if (mini < s) {
s += a[index][1];
a[index][0] = 1000000;
} else {
flag = false;
break;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int x[10001] = {0};
int main() {
int s, n;
cin >> s >> n;
set<int> v1;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
v1.insert(a);
x[a] += b;
}
int k = 0;
for (set<int>::iterator it = v1.begin(); it != v1.end(); it++) {
if (s > *it) {
s += x[*it];
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
} nd[10005];
bool comp(struct node a, struct node b) { return a.y > b.y; }
bool yes[10005] = {0};
int main() {
int s, n, flag;
scanf("%d %d", &s, &n);
for (int i = 1; i <= n; i++) scanf("%d %d", &nd[i].x, &nd[i].y);
sort(nd + 1, nd + 1 + n, comp);
for (int i = 1; i <= n; i++) {
flag = 1;
for (int j = 1; j <= n; j++)
if (s > nd[j].x && !yes[j]) {
s += nd[j].y;
yes[j] = 1;
flag = 0;
break;
}
if (flag) {
printf("NO\n");
return 0;
}
}
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct dragon {
int x, y;
bool operator<(const dragon &d) const { return x < d.x; }
};
dragon d[1001];
int main() {
int n, s;
cin >> s >> n;
for (int i = 0; i < n; ++i) {
cin >> d[i].x >> d[i].y;
}
bool f = 1;
sort(d, d + n);
for (int i = 0; i < n && f; ++i) {
if (s > d[i].x)
s += d[i].y;
else
f = 0;
}
if (f)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 15;
int n, s;
pair<int, int> a[maxn];
int main() {
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (s <= a[i].first) {
cout << "NO\n";
return 0;
} else {
s += a[i].second;
}
}
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
pair<int, int> a[n + 10];
for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a, a + n);
int i = 0;
while (s > a[i].first and i < n) {
s += a[i].second;
i++;
}
if (i == n)
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
pair<int, int> p[n];
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
sort(p, p + n);
for (int i = 0; i < n; i++) {
if (s > p[i].first)
s += p[i].second;
else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long v[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
;
long long s;
int n;
while (cin >> s >> n) {
pair<long long, long long> a[n];
for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a, a + n);
int sw = 1;
for (int i = 0; i < n && sw; i++)
if (s > a[i].first)
s += a[i].second;
else
sw = 0;
cout << (sw ? "YES" : "NO") << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int get_nim(long long x) {
if (x < 4) return 0;
if (x < 16) return 1;
if (x < 82) return 2;
if (x < 6724) return 0;
if (x < 50626) return 3;
if (x < 2562991876LL) return 1;
return 2;
}
int main() {
int n, ans = 0;
long long a;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a;
ans ^= get_nim(a);
}
if (ans)
cout << "Furlo" << endl;
else
cout << "Rublo" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005;
long long n, a[N], s[5][N], x, v;
long long s4(long long x) {
long long l = 0, r = min(x - 1, 2000LL);
while (r - l > 1) {
long long m = l + r >> 1;
if (m * m * m * m < x)
l = m;
else
r = m;
}
return l + 1;
}
long long s2(long long x) {
long long l = 0, r = min(x - 1, 2000000LL);
while (r - l > 1) {
long long m = l + r >> 1;
if (m * m > x)
r = m;
else
l = m;
}
return r - 1;
}
long long sg(long long x) {
if (x <= 1000000) return a[x];
long long t = 0, l = s4(x), r = s2(x);
while (s[t][r] - s[t][l - 1]) t++;
return t;
}
signed main() {
ios::sync_with_stdio(0);
for (long long i = 1; i <= 1000000; i++) {
if (i > 60000)
a[i] = a[i - 1];
else {
long long v[10];
for (long long j = 0; j < 10; j++) v[j] = 0;
for (long long j = s4(i); j <= s2(i); j++) v[a[j]] = 1;
for (long long j = 0;; j++) {
if (!v[j]) {
a[i] = j;
break;
}
}
}
for (long long j = 0; j < 5; j++) s[j][i] = s[j][i - 1];
s[a[i]][i]++;
}
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> x;
v ^= sg(x);
}
cout << (v ? "Furlo" : "Rublo") << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long ans = 0;
long long x, y;
for (int i = 0; i < n; i++) {
cin >> x;
if (x < 4)
y = 0;
else if (x < 16)
y = 1;
else if (x < 82)
y = 2;
else if (x < 6724)
y = 0;
else if (x < 50626)
y = 3;
else if (x < 2562991876ll)
y = 1;
else
y = 2;
ans ^= y;
}
if (ans == 0) {
cout << "Rublo\n";
} else {
cout << "Furlo\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
ios::sync_with_stdio(0);
run();
}
long long grundy[1000000];
long long grount[1000000];
long long val[1000000];
set<int> mex;
int most = 0;
void add(int x) {
if (not(grount[x]++)) mex.erase(x);
if (mex.empty()) mex.insert(++most);
}
void remove(int x) {
if (not(--grount[x])) mex.insert(x);
}
void run() {
long long n, res = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> val[i];
sort(val, val + n);
add(0);
long long l = 2, r = 2;
for (long long dst = 4; dst < 900000; dst++) {
while ((r + 1) * (r + 1) <= dst) add(grundy[++r]);
while (l * l * l * l < dst) remove(grundy[l++]);
grundy[dst] = *mex.begin();
}
for (int i = 0; i < n; i++) {
if (val[i] < 900000) {
res ^= grundy[val[i]];
} else {
while ((r + 1) * (r + 1) <= val[i]) add(grundy[++r]);
while (l * l * l * l < val[i]) remove(grundy[l++]);
res ^= *mex.begin();
}
}
cout << (res ? "Furlo" : "Rublo") << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 881927;
vector<pair<long long, long long> > v[5];
long long square[maxn];
long long power(long long aa, long long bb) {
if (pow(aa, bb) > 2e18) return 2e18;
long long x = 1, y = aa;
while (bb > 0) {
if (bb % 2) {
x = (x * y);
}
bb /= 2;
if (bb > 0) y = (y * y);
}
return x;
}
long long nthroot(long long x, double y) {
long long temp = pow(x, 1.0 / y);
while (power(temp, y) < x) ++temp;
return temp;
}
long long root(long long x) {
long long a = sqrt(x);
while (square[a + 1] <= x) a++;
return a;
}
bool g(long long l1, long long r1, long long l2, long long r2) {
if (r1 < l2 or r2 < l1) return 0;
return 1;
}
long long f(long long x) {
if (x <= 881918) {
for (long long i = 0; i < 5; ++i) {
for (auto it : v[i]) {
if (g(it.first, it.second, x, x)) return i;
}
}
}
long long a = nthroot(x, 4);
long long b = root(x);
if (b == x) b--;
if (a > b) return 0;
for (long long i = 0; i < 5; ++i) {
bool flag = 0;
for (auto it : v[i]) {
if (g(a, b, it.first, it.second)) flag = 1;
}
if (!flag) return i;
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
for (long long i = 0; i < maxn; ++i) {
square[i] = i * i;
}
v[0].emplace_back(1, 3);
v[0].emplace_back(82, 6723);
v[1].emplace_back(4, 15);
v[1].emplace_back(50626, 881918);
v[2].emplace_back(16, 81);
v[3].emplace_back(6724, 50625);
long long n;
cin >> n;
long long ans = 0;
for (long long i = 0; i < n; ++i) {
long long x;
cin >> x;
ans ^= f(x);
}
if (ans != 0) {
cout << "Furlo" << '\n';
;
} else
cout << "Rublo" << '\n';
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, res = 0, cur;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> cur;
if (cur < 4 || (cur >= 82 && cur <= 6723)) {
res = (res ^ 0);
} else if ((cur >= 4 && cur <= 15) ||
(cur >= 50626 && cur < 2562991876ll)) {
res = (res ^ 1);
} else if ((cur >= 16 && cur <= 81) || (cur >= 2562991876ll)) {
res = (res ^ 2);
} else {
res = (res ^ 3);
}
}
if (!res) {
cout << "Rublo";
} else {
cout << "Furlo";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> F[1000010];
void init() {
for (int i = 2; i <= 1000000; ++i) {
int R = sqrt(i);
int L = sqrt(R);
if (L * L * L * L < i) ++L;
int x = 0;
F[i] = F[i - 1];
for (; F[R][x] - F[L - 1][x]; ++x)
;
F[i][x]++;
}
}
void work() {
int n;
cin >> n;
int ans = 0;
while (n--) {
long long x;
scanf("%I64d", &x);
long long R = sqrt(x);
long long L = sqrt(R);
if (L * L * L * L < x) ++L;
int p = 0;
for (; F[R][p] - F[L - 1][p]; ++p)
;
ans ^= p;
}
puts(ans ? "Furlo" : "Rublo");
}
int main() {
init();
work();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int n, a, ans = 0;
void solve() {
int i, lamp = 0;
scanf("%I64d", &n);
for (i = 1; i <= n; i++) {
scanf("%I64d", &a);
if (a < 3) ans ^= 0;
if (a >= 4 && a <= 15) ans ^= 1;
if (a >= 16 && a <= 81) ans ^= 2;
if (a >= 82 && a <= 6723) ans ^= 0;
if (a >= 6724 && a <= 50625) ans ^= 3;
if (a >= 50626 && a <= 2562991875LL) ans ^= 1;
if (a >= 2562991876LL) ans ^= 2;
}
if (ans)
cout << "Furlo\n";
else
cout << "Rublo\n";
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long x;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> x;
if (x < 4)
ans ^= 0;
else if (x < 16)
ans ^= 1;
else if (x < 82)
ans ^= 2;
else if (x < 6724)
ans ^= 0;
else if (x < 50626)
ans ^= 3;
else if (x < 2562991876LL)
ans ^= 1;
else
ans ^= 2;
}
if (ans)
cout << "Furlo" << endl;
else
cout << "Rublo";
}
|
#include <bits/stdc++.h>
using namespace std;
void ga(int N, long long* A) {
for (int i(0); i < N; i++) scanf("%lld", A + i);
}
struct MEX {
int p[(4) << 1], C[(4)];
void CLR() { (memset(C, 0, sizeof(C))), (memset(p, 0, sizeof(p))); }
int st(int b, int v, int u, int B, int E) {
if (B > b || E < b) return p[u];
if (B == E) return p[u] += v;
return p[u] = st(b, v, u << 1, B, (B + E) >> 1) +
st(b, v, u << 1 | 1, (B + E) / 2 + 1, E);
}
int get() { return gt(1, 0, (4) - 1); }
int gt(int u, int B, int E) {
if (B == E) return B;
if (p[u << 1] == (B + E) / 2 - B + 1)
return gt(u << 1 | 1, (B + E) / 2 + 1, E);
return gt(u << 1, B, (B + E) >> 1);
}
void add(int I) {
if (!C[I]++) st(I, 1, 1, 0, (4) - 1);
}
void del(int I) {
if (!--C[I]) st(I, -1, 1, 0, (4) - 1);
}
} T;
int G[(1000006)] = {0, 0}, O[(1000006)], I, J, N, a, X;
long long A[(1000006)], U, V;
int main(void) {
T.CLR();
for (int k(2); k < (1000006); k++) {
while (J * J <= k) T.add(G[J++]);
while (I * I * I * I < k) T.del(G[I++]);
G[k] = T.get();
}
scanf("%d", &N), ga(N, A), sort(A, A + N), T.CLR();
for (int i(0); i < N; i++) {
if (A[i] < 2) {
X ^= G[A[i]];
continue;
}
while (V * V <= A[i]) T.add(G[V++]);
while (U * U * U * U < A[i]) T.del(G[U++]);
X ^= T.get();
}
puts(!X ? "Rublo" : "Furlo");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int cmp(double x, double y = 0, double tol = 1e-9) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
unsigned long long int intervals[20][3];
void init_intervals() {
intervals[0][0] = 0ull;
intervals[0][1] = 3ull;
intervals[0][2] = 0ull;
intervals[1][0] = 4ull;
intervals[1][1] = 15ull;
intervals[1][2] = 1ull;
intervals[2][0] = 16ull;
intervals[2][1] = 81ull;
intervals[2][2] = 2ull;
intervals[3][0] = 82ull;
intervals[3][1] = 6723ull;
intervals[3][2] = 0ull;
intervals[4][0] = 6724ull;
intervals[4][1] = 50625ull;
intervals[4][2] = 3ull;
intervals[5][0] = 50626ull;
intervals[5][1] = 2562991875ull;
intervals[5][2] = 1ull;
intervals[6][0] = 2562991876ull;
intervals[6][1] = -1ull;
intervals[6][2] = 2ull;
}
int find_nimber(unsigned long long int n) {
unsigned long long int u, l, v;
for (int i = 0; i < 7; ++i) {
l = intervals[i][0];
u = intervals[i][1];
v = intervals[i][2];
if (l <= n && n <= u) return v;
}
}
int main() {
init_intervals();
int num, nim = 0;
unsigned long long int pila;
cin >> num;
for (int i = 0; i < num; ++i) {
cin >> pila;
nim ^= find_nimber(pila);
}
cout << (nim ? "Furlo" : "Rublo") << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long N, x, res;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
scanf("%lld", &x);
if (x <= 3)
res ^= 0;
else if (x <= 15)
res ^= 1;
else if (x <= 81)
res ^= 2;
else if (x <= 6723)
res ^= 0;
else if (x <= 50625)
res ^= 3;
else if (x <= 2562991875LL)
res ^= 1;
else
res ^= 2;
}
printf((res) ? "Furlo\n" : "Rublo\n");
}
|
#include <bits/stdc++.h>
int main() {
int n, s;
scanf("%d", &n);
s = 0;
for (int i = 0; i < n; i++) {
long long x;
int y;
scanf("%I64d", &x);
if (x < 4)
y = 0;
else if (x < 16)
y = 1;
else if (x < 82)
y = 2;
else if (x < 6724)
y = 0;
else if (x < 50626)
y = 3;
else if (x < 2562991876LL)
y = 1;
else
y = 2;
s ^= y;
}
puts(s ? "Furlo" : "Rublo");
}
|
#include <bits/stdc++.h>
using namespace std;
int solve(long long x) {
if (x <= 3) return 0;
if (x <= 15) return 1;
if (x <= 81) return 2;
if (x <= 6723) return 0;
if (x <= 50625) return 3;
if (x <= 2562991875LL) return 1;
return 2;
}
int main() {
ios_base::sync_with_stdio(0);
int res = 0;
int n;
long long x;
cin >> n;
while (n--) {
cin >> x;
res ^= solve(x);
}
if (res == 0)
cout << "Rublo\n";
else
cout << "Furlo\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tos(T a) {
stringstream ss;
string ret;
ss << a;
ss >> ret;
return ret;
}
int tu(int val) { return (1 << val); }
bool iset(int mask, int id) {
if ((mask & tu(id)) != 0) return true;
return false;
}
void doset(int &mask, int id) { mask |= tu(id); }
void dounset(int &mask, int id) { mask = mask & (~tu(id)); }
vector<int> arr[882917];
int N;
int find(int ind, int l, int r) {
vector<int>::iterator it;
it = lower_bound((arr[ind]).begin(), (arr[ind]).end(), l);
if (it == arr[ind].end()) return 0;
if ((*it) <= r)
return 1;
else
return 0;
}
int main() {
for (int(i) = (0); (i) < (882917); (i)++) arr[i].clear();
for (int(i) = (0); (i) < (882917); (i)++) {
int l = ceil(sqrt(sqrt(i)));
int r = sqrt(i);
if (r == i) r--;
int v = 0;
while (find(v, l, r)) v++;
arr[v].push_back(i);
}
while (cin >> N) {
long long val, ret = 0;
for (int(i) = (0); (i) < (N); (i)++) {
cin >> val;
int l = ceil(sqrt(sqrt(val)));
int r = sqrt(val);
if (r == val) r--;
int v = 0;
while (find(v, l, r)) v++;
ret ^= v;
}
if (ret == 0)
cout << "Rublo";
else
cout << "Furlo";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
int _MINUS;
const int MXN = 882000;
const int C = 262144;
const int INF = 1000000001;
const int D = 881918;
const int Q = 5;
int mex[10];
int g[MXN];
int cnt[MXN][Q + 2];
long long int a[MXN];
int n;
void grundyCalc(int X) {
g[0] = 0;
g[1] = 0;
cnt[0][0] = 1;
cnt[1][0] = 2;
int MX = 0;
for (int j = (2); j <= (X); j++) {
int x = j;
int x1 = sqrt(x);
int x2 = pow(x, 0.25);
if (pow(x2, 4) < x) x2++;
for (int o = (0); o <= (Q); o++)
if (x1 >= x2 && cnt[x1][o] - cnt[x2 - 1][o] > 0) mex[o] = x;
int wyn = 0;
while (mex[wyn] == x) wyn++;
g[x] = wyn;
MX = max(MX, g[x]);
for (int o = (0); o <= (Q); o++) cnt[j][o] = cnt[j - 1][o] + (o == g[x]);
}
}
int main() {
grundyCalc(D);
cin >> n;
for (int i = (1); i <= (n); i++) cin >> a[i];
int XOR = 0;
for (int i = (1); i <= (n); i++) {
long long int A = a[i];
if (A < D) {
XOR ^= g[A];
continue;
}
int a1 = sqrt(A);
int a2 = (pow(A, 0.25));
if (pow(a2, 4) < A) a2++;
for (int j = (0); j <= (Q); j++) mex[j] = 0;
if (a1 >= a2) {
for (int j = (0); j <= (Q); j++)
if (cnt[a1][j] - cnt[a2 - 1][j] > 0) mex[j] = i;
int wyn = 0;
while (mex[wyn] == i) wyn++;
XOR ^= wyn;
}
}
printf(XOR ? "Furlo\n" : "Rublo\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int sum[6][891917];
int dp[891917];
int grundy(long long n) {
if (n < 891917 and dp[n]) return dp[n];
int r = sqrt(n);
int l = sqrt(sqrt(n));
if (r >= n) r--;
if (l * 1LL * l * l * l == n) l--;
int ret = 0;
while (1)
if (sum[ret][r] - sum[ret][l] <= 0)
break;
else
ret++;
if (n < 891917) {
for (int i = 0; i < 6; i++) sum[i][n] = sum[i][n - 1];
sum[ret][n]++;
dp[n] = ret;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i < 891917; i++) int p = grundy(i);
int n;
cin >> n;
long long arr[n + 5];
int ans = 0;
for (int i = 0; i < n; i++) cin >> arr[i], ans ^= grundy(arr[i]);
if (ans)
cout << "Furlo\n";
else
cout << "Rublo\n";
}
|
#include <bits/stdc++.h>
using namespace std;
class mexMap {
private:
map<int, int> S;
int MEX;
public:
mexMap() { MEX = 0; }
int get() { return MEX; }
void insert(int v) {
S[v]++;
if (v == MEX) {
map<int, int>::iterator it = S.find(v);
for (; it != S.end(); it++) {
if (MEX != it->first) break;
MEX++;
}
}
}
void erase(int v) {
S[v]--;
if (v < MEX && S[v] == 0) MEX = v;
if (S[v] == 0) S.erase(v);
}
};
long long getL(long long x) {
long long l = 0, y, r = 10000;
while (l != r) {
y = (l + r) / 2;
if (x <= y * y * y * y)
r = y;
else
l = y + 1;
}
return l;
}
long long getR(long long x) {
long long l = 0, y, r = 1000000000ll;
while (l != r) {
y = (l + r + 1) / 2;
if (y * y <= x)
l = y;
else
r = y - 1;
}
return l;
}
const int MAX = 1001000;
int dp[MAX];
long long a[MAX];
int acc[5][MAX];
int grundy(long long val) {
if (val < MAX)
return dp[val];
else {
long long l = getL(val), r = getR(val);
for (int i = 0; i < int(5); i++)
if (acc[i][r] - acc[i][l - 1] == 0) return i;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < int(n); i++) scanf("%lld", a + i);
long long l, r;
for (int x = 0; x < int(50); x++) {
l = -1;
set<int> S;
for (int y = 0; y < int(x); y++) {
if (y < x && x <= y * y * y * y && y * y <= x) {
if (l == -1) l = y;
r = y;
S.insert(dp[y]);
}
}
int cnt = 0;
for (__typeof((S).begin()) v = (S).begin(); v != (S).end(); v++) {
if (*v != cnt) break;
cnt++;
}
dp[x] = cnt;
}
mexMap S;
for (int i = l; i <= r; i++) S.insert(dp[i]);
long long x = 50;
int i = 50;
int mx = 0;
for (; x < MAX; x++) {
long long y = r;
while ((y + 1) * (y + 1) <= x) {
y++;
r++;
S.insert(dp[r]);
}
y = l;
while (x > y * y * y * y) {
S.erase(dp[l]);
y++;
l++;
}
dp[i] = S.get();
i++;
}
for (int i = 0; i < int(MAX); i++) acc[dp[i]][i]++;
for (int i = 1; i < MAX; i++)
for (int j = 0; j < int(5); j++) acc[j][i] += acc[j][i - 1];
int xr = 0;
for (int i = 0; i < int(n); i++) xr ^= grundy(a[i]);
if (xr != 0)
printf("Furlo\n");
else
printf("Rublo\n");
}
|
#include <bits/stdc++.h>
using namespace std;
const int kN = 1000 * 1000 + 1;
const int kM = 10;
int sum[kN][kM];
int gr[kN];
long long Sqrt4(long long n) {
long long l = 0, r = 10 * 1000;
while (l < r) {
long long m = (l + r) / 2;
if (m * m * m * m < n)
l = m + 1;
else
r = m;
}
return l;
}
long long Sqrt(long long n) {
long long l = 0, r = 1000 * 1000 * 1000;
while (l < r) {
long long m = (l + r + 1) / 2;
if (m * m > n)
r = m - 1;
else
l = m;
}
return l;
}
long long F(long long n, long long c, long long x, long long y) {
long long x1 = x - c + 1, y1 = y + c - 1;
long long cntX = (x1 <= 0 ? -x1 + 1 : 0);
long long cntY = (y1 - n > 0 ? y1 - n : 0);
long long res = cntX * (cntX + 1) / 2 + cntY * (cntY + 1) / 2;
long long sub = (labs(0 - x) + labs(n + 1 - y) <= c
? (c - x - n + y) * (c - x - n + y + 1) / 2
: 0);
return res - sub;
}
long long H(long long n, long long c, long long x, long long y) {
long long topX = x - c, botX = x + c;
long long rightY = y + c, leftY = y - c;
return (topX <= 0 ? -topX + 1 : 0) + (botX > n ? botX - n : 0) +
(leftY <= 0 ? -leftY + 1 : 0) + (rightY > n ? rightY - n : 0);
}
long long G(long long n, long long c, long long x, long long y) {
return F(n, c, x, y) + F(n, c, n - x + 1, y) + F(n, c, n - x + 1, n - y + 1) +
F(n, c, x, n - y + 1) + H(n, c, x, y);
}
long long BinSearch(long long n, long long c, long long x, long long y) {
long long l = 0, r = 2 * 1000 * 1000 * 1000;
while (l < r) {
long long m = (l + r) / 2;
if (m * (m + 1) * 2 + 1 - G(n, m, x, y) < c)
l = m + 1;
else
r = m;
}
return l;
}
void PreCalc() {
sum[1][0] = 1;
gr[1] = 0;
sum[2][0] = 2;
gr[2] = 0;
sum[3][0] = 3;
gr[3] = 0;
for (int n = 4; n < kN; ++n) {
int l = Sqrt4(n), r = Sqrt(n);
int cnt[kM];
for (int i = 0; i < kM; ++i) {
sum[n][i] = sum[n - 1][i];
cnt[i] = sum[r][i] - sum[l - 1][i];
}
for (int i = 0; i < kM; ++i)
if (cnt[i] == 0) {
++sum[n][i];
gr[n] = i;
break;
}
}
}
int Gr(long long n) {
if (n < kN) return gr[n];
int l = Sqrt4(n), r = Sqrt(n);
int cnt[kM];
for (int i = 0; i < kM; ++i) cnt[i] = sum[r][i] - sum[l - 1][i];
for (int i = 0; i < kN; ++i)
if (cnt[i] == 0) return i;
}
int main() {
PreCalc();
int n;
cin >> n;
int x = 0;
for (int i = 0; i < n; ++i) {
long long value;
cin >> value;
x ^= Gr(value);
}
cout << (x == 0 ? "Rublo" : "Furlo");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int foo(long long x) {
if (x < 4) return 0;
if (x < 16) return 1;
if (x < 82) return 2;
if (x < 6724) return 0;
if (x < 50626) return 3;
if (x < 2562991876LL) return 1;
return 2;
}
int main() {
int n;
while (scanf("%d", &n) == 1) {
int res = 0;
long long x;
for (int i = 0; i < (n); i++) {
scanf("%I64d", &x);
res ^= foo(x);
}
if (res)
printf("Furlo\n");
else
printf("Rublo\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int g[1000001];
vector<int> fe[1000001];
int aux[1000];
int n;
int seta(int x, int y) {
for (int i = 0; i < fe[x].size(); ++i) {
aux[i] = fe[x][i];
}
for (int i = 0; i < fe[y].size(); ++i) aux[i] -= fe[y][i];
int q = 0;
while (aux[q]) q++;
return q;
}
int main() {
cin.sync_with_stdio(false);
int mai = 0;
fe[1].resize(1);
fe[1][0] = 1;
g[1] = 0;
for (int i = 2; i < 1000000; ++i) {
fe[i] = fe[i - 1];
int ra = sqrt(i), rara = ceil(sqrt(sqrt(i)));
if (ra >= rara)
g[i] = seta(ra, rara - 1);
else
g[i] = 0;
if (g[i] == fe[i].size()) fe[i].resize(g[i] + 1);
fe[i][g[i]]++;
}
cin >> n;
int rsp = 0;
for (int i = 0; i < n; ++i) {
long long aux;
cin >> aux;
if (aux == 1) continue;
int ra = int(sqrt(aux)), rara = int(ceil(sqrt(sqrt(aux))));
if (ra >= rara) rsp ^= seta(ra, rara - 1);
}
if (rsp == 0)
printf("Rublo\n");
else
printf("Furlo\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
const int N = 1e4 + 4;
int grundy[N];
int pre[N];
int mex(set<int> se) {
for (int i = 0;; i++)
if (!se.count(i)) return i;
return -1;
}
vector<pll> ve[44];
int calc_grundy(ll x) {
for (int i = 0; i <= 3; i++) {
for (pll p : ve[i])
if (p.first <= x && x <= p.second) return i;
}
}
int main() {
ios_base::sync_with_stdio(false);
ve[0].push_back({0, 3});
ve[1].push_back({4, 15});
ve[2].push_back({16, 81});
ve[0].push_back({82, 6723});
ve[3].push_back({6724, 50624});
ve[1].push_back({50625, 2562890624});
ve[2].push_back({2562890625, 777777777777});
int n;
cin >> n;
int res = 0;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
res ^= calc_grundy(x);
}
if (res)
cout << "Furlo\n";
else
cout << "Rublo\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 881917 + 5;
const int MAX_VAL = 881917;
long long arr[MAX], arr_g[MAX], g[MAX];
int st[4 * MAX], last[MAX];
int n, last_updated;
vector<pair<int, int> > queries[MAX];
int mex(vector<int> v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = int(0); i < int(v.size()); i++) {
if (v[i] != i) {
return i;
}
}
return v.size();
}
void update(int p, int l, int r, int pos, int val) {
if (l == r) {
st[p] = val;
return;
}
int mid = (l + r) / 2;
if (pos <= mid) {
update(p * 2, l, mid, pos, val);
} else {
update(p * 2 + 1, mid + 1, r, pos, val);
}
st[p] = min(st[p * 2], st[p * 2 + 1]);
}
int query(int p, int l, int r, int pos) {
if (l == r) {
return l;
}
int mid = (l + r) / 2;
if (st[p * 2] < pos) {
return query(p * 2, l, mid, pos);
}
return query(p * 2 + 1, mid + 1, r, pos);
}
int main() {
scanf("%d", &n);
for (int i = int(1); i < int(n + 1); i++) {
scanf("%lld", arr + i);
}
for (int i = int(2); i < int(1000 + 1); i++) {
int left = ceil(sqrt(sqrt(i))), right = sqrt(i);
vector<int> guys;
for (int j = int(left); j < int(right + 1); j++) {
guys.push_back(g[j]);
}
g[i] = mex(guys);
}
for (int i = int(1001); i < int(MAX_VAL + 1); i++) {
int left = ceil(sqrt(sqrt(i))), right = sqrt(i);
queries[right].emplace_back(left, i);
}
for (int i = int(0); i < int(1000 + 1); i++) {
update(1, 0, MAX_VAL, g[i], i);
for (auto &each : queries[i]) {
g[each.second] = query(1, 0, MAX_VAL, each.first);
}
}
for (int i = int(0); i < int(1000 + 1); i++) {
queries[i].clear();
}
for (int i = int(1); i < int(n + 1); i++) {
if (arr[i] <= MAX_VAL) {
arr_g[i] = g[arr[i]];
} else {
int left = ceil(sqrt(sqrt(arr[i]))), right = sqrt(arr[i]);
queries[right].emplace_back(left, i);
}
}
for (int i = int(0); i < int(MAX_VAL + 1); i++) {
update(1, 0, MAX_VAL, g[i], i);
for (auto &each : queries[i]) {
arr_g[each.second] = query(1, 0, MAX_VAL, each.first);
}
}
long long x = 0;
for (int i = int(1); i < int(n + 1); i++) {
x ^= arr_g[i];
}
puts(x > 0 ? "Furlo" : "Rublo");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int NMax = 107777;
int N;
long long A[NMax];
int main() {
scanf("%d", &N);
int ret = 0;
for (int i = 1; i <= N; i++) {
scanf("%I64d", A + i);
if (A[i] < 4)
ret ^= 0;
else if (A[i] >= 4 && A[i] < 16)
ret ^= 1;
else if (A[i] >= 16 && A[i] <= 81)
ret ^= 2;
else if (A[i] >= 82 && A[i] <= 6723)
ret ^= 0;
else if (A[i] >= 6724 && A[i] <= 50625)
ret ^= 3;
else if (A[i] >= 50626 && A[i] < 2562890626LL)
ret ^= 1;
else
ret ^= 2;
}
if (ret == 0)
puts("Rublo");
else
puts("Furlo");
getchar();
getchar();
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.