Pagini recente » Rezultatele filtrării | Cod sursa (job #2256189)
#include <algorithm>
#include <fstream>
using namespace std;
ifstream in("minim2.in");
ofstream out("minim2.out");
float a, b;
bool cmp(pair<float, float> x, pair<float, float> y){
return x.second<y.second;
}
int main(){
int n;
float rc = 0, r;
in>>n;
pair<float, float> s[n];
for(int x = 0;x<n;x++){
in>>s[x].first;
rc+=s[x].first;
s[x].second = s[x].first;
}
in>>a>>b>>r;
for(int x = 0;x<n;x++){
s[x].second*=1 - a;
}
sort(s, s + n);
rc-=s[n - 1].second;
s[n - 1].first-=s[n - 1].second;
s[n - 1].second=s[n - 1].first*(1 - b);
int move_ = 1;
while(rc>r){
move_++;
swap(s[n - 1], s[n - 2]);
for(int x = n - 2;s[x].second > s[x + 1].second;x--)
swap(s[x], s[x - 1]);
rc-=s[n - 1].second;
s[n - 1].first-=s[n - 1].second;
s[n - 1].second=s[n - 1].first*(1 - b);
}
out<<move_;
}