QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227205 | #6135. Books | hano | WA | 0ms | 3768kb | C++14 | 1.5kb | 2023-10-27 02:00:53 | 2023-10-27 02:00:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi pair<int,ll>
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
int main(){
int t;cin>>t;
while(t--){
int n,m;cin>>n>>m;
vector<ll>v;
ll mn=1e10;
int cntz=0;
ll kk=0;
for(int i=0;i<n;i++){
ll a;cin>>a;
mn=min(mn,a);
if(i>=m&&a==0)cntz++;
if(i<m)kk+=a;
v.push_back(a);
}
ll ans=0;
for(int i=0;i<m;i++){
ans+=v[i];
}
if(m==0){
if(mn==0){
cout<<"Impossible"<<endl;
}else{
cout<<mn-1<<endl;
}
continue;
}
if(n==m){
cout<<"Richman"<<endl;
}else if(cntz){
int k=m-1;
while(cntz && k>-1){
if(v[k]){
ans-=v[k];
cntz--;
if(cntz==0){
ll mnn=1e10;
for(int i=k;i<m;i++){
if(v[i])mnn=min(mnn,v[i]);
}
ans+=mnn-1;
}
}
k--;
}
if(cntz){
cout<<"Impossible"<<endl;
}else{
cout<<ans<<endl;
}
}else{
cout<<ans+mn-1<<endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3768kb
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:
3 96 Richman Impossible
result:
wrong answer 1st lines differ - expected: '6', found: '3'