QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#492867#6135. BooksInk_baiAC ✓63ms4588kbC++141.5kb2024-07-26 16:38:202024-07-26 16:38:21

Judging History

This is the latest submission verdict.

  • [2024-07-26 16:38:21]
  • Judged
  • Verdict: AC
  • Time: 63ms
  • Memory: 4588kb
  • [2024-07-26 16:38:20]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define sca(x) scanf("%d",&x)
#define pb(x) push_back(x)
#define per(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x3f3f3f3f
#define LL long long
#define N 100005
#define MAXN 2000005
#define inf 0x3f3f3f3f
 
LL a[N];
int main()
{
    int t;
    sca(t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        int c=0;
        LL mini=0x3f3f3f3f;
        rep(i,1,n)
        {
            scanf("%lld",&a[i]);
            if(a[i]==0)c++;
            if(a[i]!=0)
            mini=min(a[i],mini);
        }
        if(n==m)puts("Richman");
        else if(c>m) puts("Impossible");
        else
        {
            if(m==0||c==m) printf("%lld\n",mini-1);
            else
            {
                LL ans=0;
                int pos;
                rep(i,1,n)
                {
                    if(a[i]==0)continue;
                    if(c<m)ans+=a[i],c++;
                    if(c==m)
                    {
                        pos=i;
                        break;
                    }
                }
                mini=0x3f3f3f3f;
                rep(j,pos+1,n)
                {
                    if(a[j]!=0)mini=min(mini,a[j]);
                }
                ans+=mini-1;
                printf("%lld\n",ans);
            }
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3888kb

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: 63ms
memory: 4588kb

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: 62ms
memory: 4564kb

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