QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720310#6135. BooksMLK2WA 50ms4060kbC++141.5kb2024-11-07 11:46:552024-11-07 11:46:55

Judging History

This is the latest submission verdict.

  • [2024-11-07 11:46:55]
  • Judged
  • Verdict: WA
  • Time: 50ms
  • Memory: 4060kb
  • [2024-11-07 11:46:55]
  • Submitted

answer

#include <bits/stdc++.h>
#define N (200000 + 10)  /*------------------ #define ------------------*/
#define M (400000 + 10)
#define MOD (1000000000 + 7)
//#define MOD (998244353)
#define INF (0x3f3f3f3f)
#define LNF (3e18)
#define mod(a,b) (((a)%(b)+(b))%(b))
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<double,double> PDD;

int n,m;
int a[N],minv;

auto solve(){
	
	cin >> n >> m;
	minv = 2e9;
	for(int i = 1;i <= n;i ++ ) cin >> a[i],minv = min(minv,a[i]);
	if(m == 0){
		int ans = minv - 1;
		if(ans < 0) cout << "Impossible\n";
		else cout << ans << '\n';
		return;
	}
	if(m == n){
		cout << "Richman\n";
		return;
	}
	int Count0 = 0;
	for(int i = 1;i <= n;i ++ )
		Count0 += (a[i] == 0);
	
	if(Count0 > m){
		cout << "Impossible\n";
		return;
	}else if(Count0 == m){
		cout << (minv - 1) << '\n';
		return;
	}else{
		m -= Count0;
	}
	
	LL ans = 0;
	int t = 0,i = 1;
	while(t < m && i <= n){
		if(a[i] == 0) i ++ ;
		else{
			t ++ ;
			ans += a[i];
			i ++ ;
		}
	}
	
	while(i <= n){
		if(a[i]){
			ans += a[i] - 1;
			break;
		}
		i ++ ;
	}
	
	cout << ans << '\n';
}

signed main(){
	IOS
	int T = 1;
	cin >> T;
	while(T -- ) solve();
	//while(T -- ) cout << (solve() ? "YES" : "NO") << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

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: 50ms
memory: 4060kb

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
-1
Impossible
99999999999999
192
80
Richman
97
490
Richman
24
163
98
30
15
Richman
Richman
Richman
111
Richman
Richman
450
168
44
350
34
513
28
202
321
Richman
Richman
Richman
212
344
2
160
76
101
91
130
3
Richman
200
32
15
Richman
21
26
Richman
88
Richman
302
356
Richman
Richman
60
313
62
343
Ric...

result:

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