이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 100000;
struct Picture{
int sz;
int value;
bool operator < (Picture const &a) const{
return sz < a.sz;
}
} v[1 + nmax];
int frame[1 + nmax];
int n, m;
int test(int target){
multiset<int> myset;
int result = 0, ptr = 1, currvalue = 0;
for(int i = m - target + 1; i <= m; i++){
while(ptr <= n && v[ptr].sz <= frame[i])
myset.insert(v[ptr++].value);
set<int>::iterator it = myset.lower_bound(currvalue);
if(it != myset.end()) {
currvalue = *it;
myset.erase(it);
} else
return 0;
}
return 1;
}
int binarysearch(int from, int to){
if(from < to){
int mid = (from + to + 1) / 2;
if(test(mid) == 1)
return binarysearch(mid, to);
else
return binarysearch(from, mid - 1);
} else
return from;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n; i++)
cin >> v[i].sz >> v[i].value;
sort(v + 1, v + n + 1);
for(int i = 1;i <= m; i++)
cin >> frame[i];
sort(frame + 1, frame + m + 1);
cout << binarysearch(0, MIN(n, m));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t2.cpp: In function 'int test(int)':
joi2019_ho_t2.cpp:25:7: warning: unused variable 'result' [-Wunused-variable]
int result = 0, ptr = 1, currvalue = 0;
^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |