이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int R, C;
vector<pii> X, Y;
vector<ll> csum;
vector<ll> psum;
ll f(ll k) {
int s = 0, e = (int)Y.size() - 1, p = -1;
while(s <= e) {
int m = (s + e)>>1;
if(Y[m].first >= k) {
p = m;
s = m + 1;
}
else e = m - 1;
}
ll ret = psum.back();
if(p != -1) {
ret += csum[p] * k;
ret -= psum[p];
}
return ret;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> R;
for(int i = 0; i < R; i++) {
int a, b; cin >> a >> b;
X.push_back(pii(a, b));
}
cin >> C;
for(int i = 0; i < C; i++) {
int a, b; cin >> a >> b;
Y.push_back(pii(a, b));
}
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
reverse(X.begin(), X.end());
reverse(Y.begin(), Y.end());
csum.resize(Y.size());
psum.resize(Y.size());
for(int i = 0; i < Y.size(); i++) {
csum[i] = Y[i].second;
psum[i] = 1LL * Y[i].first * Y[i].second;
if(i) {
csum[i] += csum[i - 1];
psum[i] += psum[i - 1];
}
}
ll sum = 0;
ll k = 0;
for(int i = 0; i < X.size(); i++) {
sum += 1LL * X[i].first * X[i].second;
k += X[i].second;
if(sum > f(k)) {
cout << 0;
return 0;
}
}
cout << 1;
}
컴파일 시 표준 에러 (stderr) 메시지
bodyguards.cpp: In function 'int main()':
bodyguards.cpp:58:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < Y.size(); i++) {
~~^~~~~~~~~~
bodyguards.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < X.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... |