#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int) 1e5 + 5;
int a[maxn];
int main(void)
{
//freopen("in.txt","r",stdin);
std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
int cnt0 = 0;
for(int i = 0;i<n;i++) cin>>a[i], !a[i]?cnt0++ : cnt0;
if(m == n) { cout<<"Richman"<<endl; continue; }
if(m<cnt0) { cout<<"Impossible"<<endl; continue; }
ll ans = 0;
int mi = inf;
m -= cnt0;
int k = 0;
while(m) a[k]? ans += a[k++], m-- :k++;
for(int i = k ;i<n ; i++) if(a[i]) mi = min(mi, a[i]);
ans += (mi - 1);
cout<<ans<<endl;
}
}
The 2018 ACM-ICPC Asia Qingdao Regional Contest —— Books(模拟 + 水题)
最新推荐文章于 2020-12-11 14:26:35 发布