QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761779 | #4233. Reset | liuziao | WA | 1ms | 7636kb | C++14 | 1.7kb | 2024-11-19 10:13:17 | 2024-11-19 10:13:18 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
const int kMaxN = 2e5 + 5;
int n, c;
std::pair<int, int> a[kMaxN];
bool check(int t) {
static std::pair<int, int> b[kMaxN];
static int tmp[kMaxN];
__int128_t now = (__int128_t)t * c;
for (int i = 1; i <= n; ++i) {
b[i] = a[i];
int cnt = std::min<__int128_t>({t, now, b[i].second / b[i].first});
b[i].second -= b[i].first * cnt;
now -= cnt;
tmp[i] = cnt;
}
if (now) {
std::vector<std::pair<int, int>> vv;
for (int i = 1; i <= n; ++i) {
if (tmp[i] < t)
vv.emplace_back(b[i].second, i);
}
std::sort(vv.begin(), vv.end(), std::greater<>());
for (auto [val, i] : vv) {
if (now) {
b[i].second = 0, --now;
}
}
}
std::vector<int> vec;
int sum = 0;
for (int i = 1; i <= n; ++i) {
sum += b[i].second;
vec.emplace_back(std::min(b[i].first, b[i].second));
}
std::sort(vec.begin(), vec.end(), std::greater<>());
for (auto x : vec) sum = std::min(sum, sum - x + 1);
return sum <= c;
}
void dickdreamer() {
std::cin >> n >> c;
for (int i = 1; i <= n; ++i) std::cin >> a[i].second >> a[i].first;
std::sort(a + 1, a + 1 + n, std::greater<>());
int L = -1, R = 1e18, res = 1e18;
while (L + 1 < R) {
int mid = (L + R) >> 1;
if (check(mid)) R = res = mid;
else L = mid;
}
std::cout << res << '\n';
}
int32_t main() {
#ifdef ORZXKR
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
int T = 1;
// std::cin >> T;
while (T--) dickdreamer();
// std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7636kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7592kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 7540kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5548kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5616kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 1ms
memory: 7604kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 4 3 5 3
output:
4
result:
ok single line: '4'
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 7604kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 7 3 5 3
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'