QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#180974 | #6135. Books | organput# | AC ✓ | 57ms | 6192kb | C++14 | 2.3kb | 2023-09-16 14:50:52 | 2023-09-16 14:50:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fo(x,a,b) for(int x=a;x<=b;x++)
#define of(x,a,b) for(int x=a;x>=b;x--)
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define PI acos(-1)
#define pb push_back
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define lbit(a) (__builtin_ffsll(a))
#define ubit(a) (64-__builtin_clzll(a))
#define fi first
#define se second
bool isprime(ll x){
if(x==1)return false;
for(ll i=2;i<=x/i;i++){
if(x%i==0)return false;
}
return true;
}
ll popcnt(ll x){
ll cnt=0;
while(x){
if(x&1)cnt++;
x>>=1;
}
return cnt;
}
ll qmi(ll a,ll b,ll p){
a%=p;
ll res=1;
while(b){
if(b&1)res=res*a%p;
a=a*a%p;
b>>=1;
}
return res;
}
ll exgcd(ll a,ll b,ll &x,ll &y){
if(!b){
x=1,y=0;
return a;
}
ll d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
const int N=2e5+10;
const int mod=1e9+7;
ll fact[N],in_fact[N];
ll C(ll n,ll m) {
if (n < m || m < 0)return 0;
return fact[n] * qmi(fact[m] * fact[n - m] % mod, mod - 2, mod) % mod;
}
//ll C(ll n,ll m){
// if (n < m || m < 0)return 0;
// return fact[n]%mod*in_fact[m]%mod*in_fact[n-m]%mod;
//}
ll a[N];
void sol(){
//memset(a,0,sizeof(a));
int n,m,cnt=0;cin>>n>>m;
ll minn=1e9+10;
fo(i,1,n){
cin>>a[i];
if(a[i]==0) cnt++;
if(a[i]) minn=min(a[i],minn);
}
if(m<cnt){
cout<<"Impossible"<<endl;
}
else if(n==m){
cout<<"Richman"<<endl;
}
else if(m==0 || m==cnt){
cout<<minn-1<<endl;
}
else{
int k=0,st=0;
ll ans=0;
for(int i=1;i<=n;i++){
if(k==m-cnt) {
st=i;break;
}
//cout<<'*'<<endl;
if(!a[i]) continue;
else{
k++;
ans+=a[i];
//cout<<ans<<'*'<<endl;
}
}
ll minn1=1e9+10;
fo(i,st,n){
if(a[i]) minn1=min(minn1,a[i]);
}
cout<<ans-1+minn1<<endl;
}
}
int main(){
close();
int t=1;
cin>>t;
while(t--){
sol();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 57ms
memory: 6192kb
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: 54ms
memory: 4360kb
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