QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526275#6135. BooksFLtheLeathermanWA 31ms4584kbC++141.6kb2024-08-21 12:53:302024-08-21 12:53:30

Judging History

This is the latest submission verdict.

  • [2024-08-21 12:53:30]
  • Judged
  • Verdict: WA
  • Time: 31ms
  • Memory: 4584kb
  • [2024-08-21 12:53:30]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
inline int read(){
    char ch=getchar();
    int num=0,f=1;
    while(!isdigit(ch)){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        num=num*10+ch-'0';
        ch=getchar();
    }
    return f>0?num:-num;
}
const int MAXN=100010;
int n,m;
int a[MAXN];
bool check(int val){
    int cnt=0;
    rep(i,1,n){
        if(val>=a[i]){
            cnt++;
            val-=a[i];
        }
    }
    return cnt<=m;
}
signed main(){
    //freopen("J.in","r",stdin);
    int T;
    cin>>T;
    int cnt=0;
    while(T--){
        cnt++;
        n=read(),m=read();
        int s=0;
        rep(i,1,n){
            a[i]=read();
            s+=a[i];
        }
        if(!check(0)){
            puts("Impossible");
            continue;
        }
        else if(m==n){
            puts("Richman");
            continue;
        }
        int l=0,r=s;
        int ans=s;
        while(l<=r){
            int mid=(l+r)/2;
            if(check(mid)){
                l=mid+1;
                ans=mid;
            }
            else r=mid-1;
        }
        printf("%lld\n",ans);
        
        if(cnt==12){
            cout<<n<<' '<<m<<endl;
            rep(i,1,n){
                cout<<a[i]<<' ';
            }
            cout<<endl;
        }
    }
}

詳細信息

Test #1:

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

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: 31ms
memory: 4584kb

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
90
6 3
65 75 23 1 25 2 
98
30
15
Richman
Richman
Richman
65
Richman
Richman
450
24
44
349
34
513
28
99
238
Richman
Richman
Richman
66
274
2
160
76
58
91
71
3
Richman
125
32
15
Richman
21
26
Richman
7
Richman
247
300
Richman
Richman
60
31...

result:

wrong answer 12th lines differ - expected: '163', found: '90'