QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#492862#6135. BooksInk_baiWA 59ms4972kbC++14991b2024-07-26 16:37:122024-07-26 16:37:13

Judging History

This is the latest submission verdict.

  • [2024-07-26 16:37:13]
  • Judged
  • Verdict: WA
  • Time: 59ms
  • Memory: 4972kb
  • [2024-07-26 16:37:12]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int val[maxn];
int n,m;
void solve()
{
    cin>>n>>m;
    int sum=0;
    int cnt=0, ans=0;
    int minn=0x3f3f3f3f;
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        if(val[i]==0) cnt++;
        if(val[i]!=0) minn=min(val[i],minn);
        sum+=val[i];
    }
    if(m==0) {cout<<minn-1<<endl;return;}
    if(n==m) {cout<<"Richman"<<endl;return;}
    if(cnt>m) {cout<<"Impossible"<<endl;return;}
    m -= cnt;
    vector<int> nonZeroVals;
    for(int i=1;i<=n;i++)
    {
        if(val[i]!=0) nonZeroVals.push_back(val[i]);
    }
    sort(nonZeroVals.begin(), nonZeroVals.end());
    for(int i=0; i<m; i++)
    {
        ans += nonZeroVals[i];
    }
    cout << ans + nonZeroVals[m] - 1 << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
38
56
Richman
97
411
Richman
24
50
98
30
15
Richman
Richman
Richman
36
Richman
Richman
450
24
44
349
34
475
28
33
238
Richman
Richman
Richman
51
274
2
160
76
47
91
71
3
Richman
125
32
15
Richman
21
26
Richman
7
Richman
206
266
Richman
Richman
60
286
62
257
Richman
67
Ri...

result:

wrong answer 5th lines differ - expected: '192', found: '38'