QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720307 | #6135. Books | MLK2 | TL | 0ms | 3652kb | C++14 | 1.5kb | 2024-11-07 11:46:07 | 2024-11-07 11:46:08 |
Judging History
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...