QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#180928#6135. Booksorganput#WA 57ms4380kbC++142.2kb2023-09-16 14:24:392023-09-16 14:24:40

Judging History

This is the latest submission verdict.

  • [2023-09-16 14:24:40]
  • Judged
  • Verdict: WA
  • Time: 57ms
  • Memory: 4380kb
  • [2023-09-16 14:24:39]
  • Submitted

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(){
    ll n,m;cin>>n>>m;
    ll cnt=0,z=0,z0=0;
    ll minn=1e9;
    ll minn0=1e9;
    fo(i,1,n){
        ll x;cin>>x;
        a[i]=x;
        if(x==0) z++;
        minn=min(minn,x);
        if(i<=m){
            cnt+=x;
        }
        else{
            if(x==0) z0++;
            else minn0=min(minn0,x);
        }
    }
    //cout<<n<<' '<<m<<endl;
    if(m<z){
        cout<<"Impossible"<<endl;
    }
    else if(n==m){
        cout<<"Richman"<<endl;
    }
    else if(m==0){
        cout<<minn-1<<endl;
    }
    else{
        if(z0){
            cnt=0;
            fo(i,1,n){
                if(i<=m-z0) cnt+=a[i];
                else if(a[i]!=0) minn0=min(minn0,a[i]);
            }
        }
        cout<<cnt+minn0-1<<endl;
    }
    return;
}

int main(){
    close();
    int t=1;
    cin>>t;
    while(t--){
        sol();
    }
}

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: 0
Accepted
time: 53ms
memory: 4380kb

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: -100
Wrong Answer
time: 57ms
memory: 4380kb

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:

wrong answer 551st lines differ - expected: '8', found: '108'