#include <iostream>
using namespace std;
struct ura{
int x, y;
};
ura v[105];
int l[105];
int scad[105];
///2^j +....
int main()
{
int n, i, j, b, p, sol = 0;
cin >> n >> p;
for (i = 1; i <= p; i++)
{
cin >> l[i];
l[i] += l[i - 1];
}
for (i = 1; i <= n; i++)
cin >> v[i].x >> v[i].y;
for (i = 30; i >= 0; i--)
{
int ok = 1;
int put = (1 << i);
for (b = 1; b <= p && ok; b++)
{
scad[b] = 0;
ok = 0;
for (j = l[b - 1] + 1; j <= l[b]; j++)
{
if (v[j].y >= put && (!scad[b] || v[j].x >= put))
{
ok = 1;
scad[b] = j;
}
}
}
if (ok)
{
sol += put;
for (b = 1; b <= p; b++)
v[scad[b]].x = max(v[scad[b]].x, put);
}
for (j = 1; j <= n; j++)
if (v[j].x >= put)
{
v[j].x -= put;
v[j].y -= put;
}
}
cout << sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |