# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779602 | 79brue | Bodyguards (CEOI10_bodyguards) | C++17 | 74 ms | 8380 KiB |
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>
using namespace std;
typedef long long ll;
int n, m;
pair<ll, ll> a[200002];
pair<ll, ll> b[200002];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%lld %lld", &a[i].first, &a[i].second);
scanf("%d", &m);
for(int i=1; i<=m; i++) scanf("%lld %lld", &b[i].first, &b[i].second);
sort(a+1, a+n+1), reverse(a+1, a+n+1);
sort(b+1, b+m+1), reverse(b+1, b+m+1);
ll level = 0; /// 초기 시작 위치
ll limit = m; /// 오른쪽 한계
ll limitSum = 0;
ll cur = 0; /// 현재 채운 칸 위치
for(int i=1; i<=m; i++) limitSum += b[i].second;
for(int i=1; i<=n; i++){
ll v = a[i].first * a[i].second;
while(v){
if(a[i].first > limitSum && !(v < a[i].first && b[limit+1].first >= a[i].first)){
puts("0");
return 0;
}
ll tmp = min(v, (b[limit].first - level) * limitSum - cur);
v -= tmp;
level += (cur + tmp) / limitSum, cur = (cur + tmp) % limitSum;
if(b[limit].first<=level) limitSum -= b[limit].second, limit--;
}
}
puts("1");
}
Compilation message (stderr)
# | 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... |