이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct event {
int l, r;
bool operator < ( const event e ) const {
if ( l == e.l )
return r < e.r;
return l < e.l;
}
};
const int MAX_N = 1e5;
event events[MAX_N + 1];
set<event> selectedEvents;
bool check ( event e ) {
auto p = selectedEvents.lower_bound( e );
if ( !(p == selectedEvents.end() || e.r <= p->l) )
return false;
if ( !(p == selectedEvents.begin() || (--p)->r <= e.l) )
return false;
return true;
}
int main() {
int n, k;
cin >> n >> k;
for ( int i = 1; i <= n; i++ )
cin >> events[i].l >> events[i].r;
vector<int> ans;
for ( int i = 1; i <= n && k > 0; i++ ) {
if ( !check( events[i] ) )
continue;
vector<event> queryEvents;
for ( int j = i + 1; j <= n; j++ ) {
if ( check( events[j] ) )
queryEvents.push_back( events[j] );
}
sort( queryEvents.begin(), queryEvents.end(), []( event a, event b ) {
if ( a.r == b.r )
return a.l < b.l;
return a.r < b.r;
} );
int x = 0, t = 0;
for ( event e: events ) {
if ( e.l >= t ) {
x++;
t = e.r;
}
}
if ( x >= k - 1 ) {
ans.push_back( i );
selectedEvents.insert( events[i] );
k--;
}
}
if ( k > 0 ) {
cout << -1;
return 0;
}
for ( int i: ans )
cout << i << "\n";
return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |