#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 2100;
#define int long long
vector<pair<int,int>> v;
int sg[4*MAXN], lazy[4*MAXN];
void init(int k, int a, int b) {
if (a == b) {
sg[k] = a;
lazy[k] = 0;
return ;
}
init(2*k, a, (a+b)/2);
init(2*k+1, (a+b)/2+1, b);
sg[k] = min(sg[2*k], sg[2*k+1]);
lazy[k] = 0;
}
void push(int k, int a, int b) {
if (lazy[k]) {
sg[k] += lazy[k];
if (a != b) {
lazy[2*k] += lazy[k];
lazy[2*k+1] += lazy[k];
}
lazy[k] = 0;
}
}
void update(int k, int a, int b, int q_l, int q_r, int val) {
push(k, a, b);
if (b < q_l || a > q_r)
return ;
if (q_l <= a && b <= q_r) {
lazy[k] += val;
push(k, a, b);
return ;
}
update(2*k, a, (a+b)/2, q_l, q_r, val);
update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
sg[k] = min(sg[2*k], sg[2*k+1]);
}
int query(int k, int a, int b, int q_l, int q_r) {
push(k, a, b);
if (b < q_l || a > q_r)
return 1e9;
if (q_l <= a && b <= q_r)
return sg[k];
return min(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}
struct Partition {
int n = 2100;
vector<int> ban, here;
int cnt = 0, cost = 0, fully_active = -1;
Partition(vector<int> _ban) : ban(_ban) {
n = ban.size();
cnt = cost = 0;
fully_active = -1;
for (int i = n-1; i >= 0; i--) {
if (ban[i])
fully_active = i;
}
init(1, 1, n);
for (int i = 0; i < n; i++) {
if (ban[i] || query(1, 1, n, v[i].s, n) == 0)
continue;
cnt++;
cost += v[i].f;
here.push_back(i);
update(1, 1, n, v[i].s, n, -1);
}
}
};
bool operator <(Partition A, Partition B) {
if (A.cnt == B.cnt && A.cost == B.cost)
return false;
return make_pair(-A.cnt, A.cost) > make_pair(-B.cnt, B.cost);
}
signed main() {
fast;
int n, k;
cin >> n >> k;
v = vector<pair<int,int>>(n);
for (int i = 0; i < n; i++)
cin >> v[i].f >> v[i].s;
sort(v.begin(), v.end());
priority_queue<Partition> pq;
pq.push(vector<int>(n));
while (!pq.empty()) {
Partition Q = pq.top();
pq.pop();
cout << Q.cnt << " " << Q.cost << "\n";
k--;
if (k == 0)
exit(0);
vector<int> ban_here = Q.ban;
for (auto u : Q.here) {
if (u <= Q.fully_active)
continue;
ban_here[u] = true;
pq.push(Partition(ban_here));
ban_here[u] = false;
}
}
for (int i = 0; i < k; i++)
cout << "0 0\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
982 ms |
59720 KB |
Output is correct |
2 |
Correct |
1079 ms |
63056 KB |
Output is correct |
3 |
Correct |
880 ms |
54608 KB |
Output is correct |
4 |
Correct |
879 ms |
55124 KB |
Output is correct |
5 |
Correct |
1067 ms |
62292 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
8 ms |
1112 KB |
Output is correct |
10 |
Correct |
213 ms |
21460 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
7912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2136 KB |
Output is correct |
2 |
Incorrect |
47 ms |
6992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
982 ms |
59720 KB |
Output is correct |
28 |
Correct |
1079 ms |
63056 KB |
Output is correct |
29 |
Correct |
880 ms |
54608 KB |
Output is correct |
30 |
Correct |
879 ms |
55124 KB |
Output is correct |
31 |
Correct |
1067 ms |
62292 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
608 KB |
Output is correct |
35 |
Correct |
8 ms |
1112 KB |
Output is correct |
36 |
Correct |
213 ms |
21460 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Incorrect |
42 ms |
7912 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |