https://ac.nowcoder.com/acm/contest/321/L
n虽然1e9 但是k<=300个罐子 买m个
a[i]<=1000 枚举钱数3e5
k=3个罐子
7 4 2
n=10
二分的话 钱数增 个数不一定增
n=10 2
n=9 2
n=8 1
n=7 1
n=6 2
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
ll n,m,k,a[maxn],cnt;
//枚举钱数 k=300个1000 最大3e5 钱数不枚举0 虽然有0
int main(){
IO;
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
cin>>a[i];
}
ll num=min(n,k*1000);
for(int i=1;i<=num;i++){ //枚举钱数
ll q=i;
cnt=0;
for(int j=1;j<=k;j++){
if(q>=a[j]){
cnt++;
q-=a[j];
}
if(q==0)
break;
}
if(cnt>=m)
{
return cout<<i<<endl,0;
}
}
//到最大钱数都买不了m个罐子 钱数较小 罐子比较贵
cout<<"poor chicken tail wine!"<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
ll n,m,k,a[maxn],cnt;
//枚举钱数 k=300个1000 最大3e5 钱数不枚举0 虽然有0
bool check(ll x){
ll cnt=0;
for(int i=1;i<=k;i++){
if(x>=a[i]){
cnt++;
x-=a[i];
}
if(cnt>=m || x==0) break;
}
return cnt>=m;
}
int main(){
IO;
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
cin>>a[i];
}
ll num=min(n,k*1000);
for(int i=1;i<=num;i++){
if(check(i)){
cout<<i<<endl;
return 0;
}
}
cout<<"poor chicken tail wine!"<<endl;
return 0;
}