QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720326#6135. BooksMLK2AC ✓55ms4064kbC++141.6kb2024-11-07 11:55:402024-11-07 11:55:41

Judging History

This is the latest submission verdict.

  • [2024-11-07 11:55:41]
  • Judged
  • Verdict: AC
  • Time: 55ms
  • Memory: 4064kb
  • [2024-11-07 11:55:40]
  • 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){
		int v = 2e9;
		for(int i = 1;i <= n;i ++ )
			if(a[i])
				v = min(v,a[i]);
		cout << (v - 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 ++ ;
		}
	}
	
	minv = 2e9;
	while(i <= n){
		if(a[i]){
			minv = min(minv,a[i]);
		}
		i ++ ;
	}
	
	cout << ans + minv - 1 << '\n';
}

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

    return 0;
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 50ms
memory: 4052kb

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
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
276
Richman...

result:

ok 10012 lines

Test #3:

score: 0
Accepted
time: 55ms
memory: 4064kb

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
Richman
Impossible
697
123
Richman
Impossible
Richman
335
Richman
Impossible
Richman
486
Richman
Impossible
57
41
Richman
Impossible
42
Richman
Richman
99
106
Richman
Richman
Impossible
Richman
Richman
Richman
Impossible
164
26
Richman
43
Richman
Richman
Richman
Impossi...

result:

ok 10012 lines