QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#492694#6135. BooksInk_baiWA 59ms4428kbC++141.3kb2024-07-26 15:19:442024-07-26 15:19:45

Judging History

This is the latest submission verdict.

  • [2024-07-26 15:19:45]
  • Judged
  • Verdict: WA
  • Time: 59ms
  • Memory: 4428kb
  • [2024-07-26 15:19:44]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 10;
int val[maxn];
int n, m;

bool check(int num) {
    int cntt = 0;
    for (int i = 1; i <= n; i++) {
        if (num >= val[i]) {
            num -= val[i];
            cntt++;
        }
    }
    if (cntt <= m) return true;
    else return false;
}

void solve() {
    cin >> n >> m;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        val[i] = 0;
    }
    int cnt = 0;
    int minn = LLONG_MAX;
    for (int i = 1; i <= n; i++) {
        cin >> val[i];
        if (val[i] == 0) cnt++;
        minn = min(val[i], minn);
        sum += val[i];
    }
    if (m == 0) {
        if (cnt == n) cout << "Impossible" << endl;
        else cout << minn - 1 << endl;
        return;
    }
    if (n == m) {
        cout << "Richman" << endl;
        return;
    }
    if (cnt > m) {
        cout << "Impossible" << endl;
        return;
    }
    int l = 0, r = sum + 1;
    while (l + 1 < r) {
        int mid = l + r >> 1;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << l << endl;
    return;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

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: 59ms
memory: 4428kb

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
103
80
Richman
97
460
Richman
24
90
98
30
15
Richman
Richman
Richman
65
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
R...

result:

wrong answer 5th lines differ - expected: '192', found: '103'