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;
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... |