This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
vector<ll> v(1, 0); // pocty riadkov po ktorych sa musime pozriet na to ako sa funkcia vyvyja
int r;
cin >> r;
vector<pair<ll, ll> > vr(r); // {dlzka, pocet} -> pocet bude postupne stupat
for (int i = 0; i < r; i++) cin >> vr[i].first >> vr[i].second;
sort(vr.begin(), vr.end(), greater<pair<ll, ll> > ());
for (int i = 0; i < r; i++)
{
if (i) vr[i].second += vr[i-1].second;
v.push_back(vr[i].second);
}
int c;
cin >> c;
vector<pair<ll, ll> > vc(c); // {dlzka, pocet} -> pocet bude postupne klesat
for (int i = 0; i < c; i++) cin >> vc[i].first >> vc[i].second;
sort(vc.begin(), vc.end());
for (int i = c - 1; i >= 0; i--)
{
if (i < c - 1) vc[i].second += vc[i+1].second;
v.push_back(vc[i].first);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
ll delta = 0, ir = 0, ic = 0;
for (int i = 1; i < v.size(); i++)
{
ll cnt = v[i] - v[i-1];
while (ir < r && vr[ir].second < v[i]) ir++;
ll cr = vr[ir].first * cnt; // kolko bodyguardov chcu mat nove riadky
while (ic < c && vc[ic].first < v[i]) ic++; // kym mame prilis malu vysku
ll cc = 0;
if (ic < c) cc = vc[ic].second * cnt; // kolko bodyguardov maju nove stlpce
delta += cc - cr;
if (delta < 0)
{
cout << "0\n";
return 0;
}
}
cout << "1\n";
return 0;
}
Compilation message (stderr)
bodyguards.cpp: In function 'int main()':
bodyguards.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |