QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#256790 | #6135. Books | He2717970784 | WA | 78ms | 4500kb | C++17 | 1.1kb | 2023-11-18 21:48:54 | 2023-11-18 21:48:54 |
Judging History
answer
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N = 1e5 + 9, INF = 2e18;
int a[N];
int n, m;
int judge(int x) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (a[i] <= x) {
x -= a[i];
cnt++;
}
if (cnt > m) {
return 1;
}
}
if (cnt < m) {
return -1;
}
return 0;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int left = 0, right = INF, ans = 0;
while (left <= right) {
int mid = (left + right) >> 1;
int x = judge(mid);
if (x == 1) {
right = mid - 1;
}
else if(x == 0){
ans = mid;
left = mid + 1;
}
else {
left = mid + 1;
}
}
int num = 0, tmp = ans;
for (int i = 1; i <= n; i++) {
if (a[i] <= tmp) {
tmp -= a[i];
num++;
}
}
if (num != m) {
cout << "Impossible\n";
}
else if (num == n) {
cout << "Richman\n";
}
else {
cout << ans << '\n';
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0);
int t = 0;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
4 4 2 1 2 4 8 4 0 100 99 98 97 2 2 10000 10000 5 3 0 0 0 0 1
output:
6 96 Richman Impossible
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 78ms
memory: 4500kb
input:
10012 1 0 2 3 2 0 1 0 2 1 0 0 100000 99999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
output:
1 0 Impossible 99999999999999 38 80 Richman 97 460 Richman 24 50 98 30 15 Richman Richman Richman 54 Richman Richman 450 24 44 349 34 513 28 99 238 Richman Richman Richman 66 274 2 160 76 58 91 71 3 Richman 125 32 15 Richman 21 26 Richman 7 Richman 247 300 Richman Richman 60 312 62 276 Richman 67 Ri...
result:
wrong answer 5th lines differ - expected: '192', found: '38'