QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720307#6135. BooksMLK2TL 0ms3652kbC++141.5kb2024-11-07 11:46:072024-11-07 11:46:08

Judging History

This is the latest submission verdict.

  • [2024-11-07 11:46:08]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3652kb
  • [2024-11-07 11:46:07]
  • 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;
		}
	
	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: 3652kb

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
Time Limit Exceeded

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:


result: