Pagini recente » Planificare infoarena | Cod sursa (job #3281114) | Cod sursa (job #3280930) | Jobs | Cod sursa (job #2913648)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin( "patrate3.in" );
ofstream fout( "patrate3.out" );
const int MAXN = 1001;
struct val {
int c, add;
} v[2 * MAXN];
struct cmp {
bool operator () ( const val &a, const val &b ) {
return a.c < b.c;
}
};
int main() {
int n, a, b, h;
fin >> n >> h;
for ( int i = 0; i < n; ++i ) {
fin >> a >> b;
b = a + b;
v[i << 1].c = a;
v[(i << 1) + 1].c = b;
v[i << 1].add = 1;
v[(i << 1) + 1].add = -1;
}
v[2 * n].c = n;
n <<= 1;
sort( v, v + n, cmp() );
int col = 0, qh = 0, maxl = 0, l = 0, colm = 0;
for ( int i = 0; i < n; ++i ) {
qh += v[i].add;
if ( qh >= h ) {
l += v[i + 1].c - v[i].c;
} else {
if ( l > maxl ) {
maxl = l;
colm = col;
}
col = v[i + 1].c;
l = 0;
}
}
fout << colm << " " << maxl;
fin.close();
fout.close();
return 0;
}