QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643777#6135. BookslhfgghcWA 91ms4548kbC++14817b2024-10-16 00:07:462024-10-16 00:07:46

Judging History

This is the latest submission verdict.

  • [2024-10-16 00:07:46]
  • Judged
  • Verdict: WA
  • Time: 91ms
  • Memory: 4548kb
  • [2024-10-16 00:07:46]
  • Submitted

answer

#include <bits/stdc++.h>
typedef long long ll;

const int N = 1e5 + 10;
int n, m;
ll a[N];

bool check(ll x) {
	ll now = x;
	ll s = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] <= now) {
			s += 1;
			now -= a[i];
		}
	}
	if (s <= m) return true;
	else return false;
}

void solve() {
	std::cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		std::cin >> a[i];
	}
	ll l = -1, r = 1e18;
	while (l < r) {
		ll mid = (l + r + 1) / 2;
		if (check(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	if (l == 1e18) {
		printf("Richman\n");
	} else if (l == -1) {
		printf("Impossible\n");
	} else {
		printf("%lld\n", l);
	}
}


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 91ms
memory: 4548kb

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'