LoginSignup
0
0

More than 3 years have passed since last update.

JOI 2011 予選 C 最高のピザ

Posted at

問題

見た感じ

具材のカロリー順にソートしてgreedyでよさそう

解法

greedy

ソースコード

const int N_MAX=103;
int n,a,b,c,calo[N_MAX];

int main(){
    int i;
    //入力
    cin>>n;
    cin>>a>>b;
    cin>>c;
    rep(i,n){
        cin>>calo[i];
    }
    //処理
    sort(calo,calo+n,greater<int>());
    double cost=a,calory=c;
    i=0;
    double ans=0,nans=calory/cost;
    do{
        ans=nans;
        cost+=b;
        calory+=calo[i];
        i++;
        nans=calory/cost;
    }while(nans>ans);
    //出力
    int res=ans;
    cout << res <<endl;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0