QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185124 | #6135. Books | Carpe_Diem | RE | 0ms | 0kb | C++20 | 1.6kb | 2023-09-21 17:37:18 | 2023-09-21 17:37:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i128=__int128_t;
#define inf 0x3f3f3f3f
#define quick std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
typedef long long ll;
typedef pair<ll,ll> PII;
typedef unsigned long long ull;
#define N 1000010
#define M 998244353
// 998244353 1000000007 1073741824
// 无序map unordered_map
int n,m;
int a[N];
ll judge(ll num){
int res=0;
for(int i=1;i<=n;i++){
if(num>=a[i]){
num-=a[i];
res++;
}
}
return res;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
if(n==m){
cout<<"Richman"<<endl;
return;
}
ll l=0,r=1e18;
while(l<=r){
ll mid=l+r>>1;
int tt=judge(mid);
// if(tt==m)break;
if(tt<m){
l=mid+1;
}else{
r=mid-1;
}
}
// 这个l是最小的
// cout<<"l ***"<<l<<endl;
int pos=-1,tnum=inf;
ll tn=l,tm=0;
for(int i=1;i<=n;i++){
if(tn>=a[i]){
tm++;
tn-=a[i];
}else{
if(a[i]<tnum){
tnum=a[i];
pos=i;
}
}
}
// cout<<"pos ***"<<pos<<endl;
if(tm>m||tm<m){
cout<<"Impossible"<<endl;
return;
}
ll ans=l+a[pos]-1;
cout<<ans<<endl;
}
int main(){ quick
int t=1;
cin>>t;
while(t--){
solve();
}
system("pause");
return 0;
}
/*
4
4 2
1 2 4 8
4 0
100 99 98 97
2 2
10000 10000
5 3
0 0 0 0 1
*/
詳細信息
Test #1:
score: 0
Dangerous Syscalls
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