Untitled
int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> a >> b; int mind = 1e9; ctung[0] = 0; ctruc[0] = 0; for ( int i = 1; i <= n; i++) cin >> d[i] >> k[i]; for ( int i = 1; i <= n - 1; i++) for ( int j = i + 1; j <= n; j++) if ( d[i] > d[j] ) { swap(d[i], d[j]); swap(k[i], k[j]); } for ( int i = 1; i <= n; i++) if ( k[i] == 1 ) { ctung[i] = ctung[i - 1] + 1; ctruc[i] = ctruc[i - 1]; } else { ctruc[i] = ctruc[i - 1] + 1; ctung[i] = ctung[i - 1]; } for ( int i = 1; i <= n; i++) { int t = i + 1; while ( t <= n && (( ctung[t] - ctung[i] < a ) || (ctruc[t] - ctruc[i] < b)) ) t++; if ( t <= n && d[t] - d[i] < mind ) { mind = d[t] - d[i] } } cout << mind; }
Leave a Comment