QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94969#6135. Booksysghwzp#WA 97ms3704kbC++14854b2023-04-08 15:12:352023-04-08 15:12:35

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 15:12:35]
  • Judged
  • Verdict: WA
  • Time: 97ms
  • Memory: 3704kb
  • [2023-04-08 15:12:35]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
int n,m,a[N];
bool check(ll x){
	int k=m;
	For(i,1,n){
		//if(x==0)cout<<i<<" "<<k<<" fjz"<<endl;
		if(!k){
			if(x>=a[i])return 0;
		}else{
			if(a[i]>=x)return 1;
			x-=a[i]; k--;
		}
	}
	return 1;
	assert(0);
}
int get(ll x){
	int k=0;
	For(i,1,n){
		if(x>=a[i]){x-=a[i]; k++;}
	}
	return k;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--){
		cin>>n>>m;
		For(i,1,n)cin>>a[i];
		if(m==n){
			cout<<"Richman\n"; continue;
		}
		//cout<<check(0)<<endl;
		ll l=0,r=1e18;
		while(l<r){
			ll mid=(l+r)>>1; mid++;
			if(check(mid))l=mid; else r=mid-1;
		}
		
		if(get(l)==m)cout<<l<<endl;
		else cout<<"Impossible\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3420kb

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: 97ms
memory: 3704kb

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
Impossible
Impossible
99999999999999
192
80
Richman
97
460
Richman
24
163
98
30
15
Richman
Richman
Richman
65
Richman
Richman
450
98
44
349
34
513
28
161
297
Richman
Richman
Richman
147
274
2
160
76
58
91
130
3
Richman
175
32
15
Richman
21
26
Richman
65
Richman
247
356
Richman
Richman
60
312
62
27...

result:

wrong answer 2nd lines differ - expected: '0', found: 'Impossible'