ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215142 | #2441. 物品 | ThySecret | 0 | 1850ms | 21232kb | C++11 | 2.2kb | 2024-11-26 20:11:08 | 2024-11-26 23:03:47 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);
typedef long long LL;
typedef pair<int, int> PII;
const int N = 500010;
const int INF = 0x3f3f3f3f;
template<typename Type>
inline void read(Type &res)
{
res = 0;
int ch = getchar(), flag = 0;
while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }
int n, C;
array<int, 2> a[N];
bool check(int mid)
{
priority_queue<int, vector<int>, greater<int>> heap;
for (int i = 1; i <= n; i ++)
if (a[i][0] >= mid) heap.emplace(a[i][1]);
if (heap.size() < mid) return false;
int cur = 0, cnt = 0;
while (!heap.empty() && cnt < mid)
{
if (cur + heap.top() <= C)
cnt ++, cur += heap.top(), heap.pop();
else return false;
}
return cnt >= mid;
}
void print(int res)
{
priority_queue<PII, vector<PII>, greater<PII>> heap;
for (int i = 1; i <= n; i ++)
if (a[i][0] >= res) heap.emplace(a[i][1], i);
printf("%d\n%d\n", res, res);
int cur = 0, cnt = 0;
while (!heap.empty() && cnt < res)
{
if (cur + heap.top().x <= C)
{
printf("%d ", heap.top().y);
cnt ++, cur += heap.top().x, heap.pop();
}
}
}
signed main()
{
read(n, C);
for (int i = 1; i <= n; i ++) read(a[i][0], a[i][1]);
sort(a + 1, a + 1 + n, [](const array<int, 2> &a, const array<int, 2> &b) { return a[0] == b[0] ? a[1] < b[1] : a[0] < b[0]; });
int l = 0, r = n, res = 0;
while (l <= r)
{
int mid = l + r >> 1;
if (check(mid)) res = mid, l = mid + 1;
else r = mid - 1;
}
print(res);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1208kb
input:
18 1024 8 3 8 1 16 9 17 6 2 5 12 3 1 7 7 9 17 1 14 3 2 7 17 5 2 3 2 5 2 10 8 3 2 3 17 5
output:
8 8 9 15 10 11 12 13 16 17
result:
wrong answer Incorrect solution!
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1208kb
input:
20 79841 15 4337 9 6289 7 9927 12 1468 7 9390 12 9228 7 5646 8 3438 3 1614 3 7048 10 8840 15 2349 16...
output:
10 10 13 16 14 17 18 11 19 12 15 20
result:
wrong answer Incorrect solution!
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 1264kb
input:
1888 987654 1082 243 1341 309 1524 959 324 593 894 952 1428 587 1367 91 1669 683 616 866 958 791 172...
output:
949 949 1319 1722 1623 1205 1592 1782 1236 1613 1863 1190 1595 1586 1350 1736 1250 945 1106 1558 115...
result:
wrong answer Incorrect solution!
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 1264kb
input:
1999 12000000 1112 2799 524 6890 686 6713 1803 4478 940 4341 1391 8972 953 592 454 7711 524 8224 127...
output:
978 978 1558 1414 1379 1499 1867 1739 1430 1647 1598 1377 1841 1378 1851 1436 1451 1571 1540 1038 15...
result:
wrong answer Incorrect solution!
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 1264kb
input:
2000 9788123 296 3976 154 3441 78 9146 1443 6444 1799 2843 1482 6843 1526 3159 1956 9324 1442 1001 5...
output:
997 997 1878 1956 1528 1949 1645 1488 1036 1765 1599 1661 1717 1809 1248 1960 1194 1907 1474 1244 12...
result:
wrong answer Incorrect solution!
Test #6:
score: 0
Wrong Answer
time: 148ms
memory: 7308kb
input:
200000 87654321 33240 503 90721 868 64272 858 170928 616 92246 213 50575 59 148252 954 87639 739 328...
output:
100168 100168 100397 101498 103700 103732 104286 104480 104709 105708 106720 106876 107266 108093 10...
result:
wrong answer Incorrect solution!
Test #7:
score: 0
Wrong Answer
time: 185ms
memory: 7832kb
input:
200000 987654321 199051 7573 6332 5631 35615 9816 185684 9227 198894 8029 185684 2173 54203 2887 107...
output:
98978 98978 122428 134270 138505 148014 153135 166563 175988 187887 192498 103421 108231 109738 1160...
result:
wrong answer Incorrect solution!
Test #8:
score: 0
Wrong Answer
time: 339ms
memory: 14032kb
input:
444444 998244353 243276 2272 436596 1761 70822 1547 263965 942 280972 2658 87160 421 268504 2945 103...
output:
222615 222615 228450 229425 230346 230912 237530 237917 239187 241874 242714 244372 244759 245418 24...
result:
wrong answer Incorrect solution!
Test #9:
score: 0
Wrong Answer
time: 385ms
memory: 17004kb
input:
500000 999999999 131412 807 486292 804 462352 1139 52896 196 426775 1655 18059 2099 224414 1308 2851...
output:
254580 254580 238845 238846 238847 238848 238849 238850 238851 238852 238853 250793 251214 251679 25...
result:
wrong answer Incorrect solution!
Test #10:
score: 0
Wrong Answer
time: 790ms
memory: 21232kb
input:
500000 1000000000 42362 5090 327916 7618 221602 679 295161 1419 69703 4221 108614 6788 210597 6940 2...
output:
231450 231450 232104 232937 253692 257275 286505 289921 355514 401047 413558 418149 418400 439706 44...
result:
wrong answer Incorrect solution!