Cod sursa(job #514365)

Utilizator vladtarniceruVlad Tarniceru vladtarniceru Data 18 decembrie 2010 15:40:52
Problema Minim2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
# include <fstream>
# include <algorithm>
  using namespace std;
    double v[100100], a, b, rec, s;
	int n, op = 1;
	inline bool cmp (double a, double b){
		return a > b;
	}
	inline int dad (int son){
		return (son >> 1);
	}
	inline int son1 (int dad){
		return (dad << 1);
	}
	inline int son2 (int dad){
		return (dad << 1) + 1;
	}
	void doHE (){
		int p = 1;
		for (;;){
			int x = son1 (p), y = son2 (p);
			if (v[x] > v[y] && v[x] > v[p]){
				double aux = v[p];
				v[p] = v[x];
				v[x] = aux;
				p = x;
			}
			else
			if (v[x] < v[y] && v[y] > v[p]){
				double aux = v[p];
				v[p] = v[y];
				v[y] = aux;
				p = y;
			}
			else
				break ;
		}
	}
    int main (){
		ifstream f ("minim2.in");
		f >> n;
		for (int i = 1; i <= n; ++i) f >> v[i], s += v[i];
		f >> a >> b >> rec;
		sort (v + 1, v + n + 1, cmp);
		s -= v[1];
		v[1] = v[1] * a;
		s += v[1];
		doHE ();
		while (s > rec){
			s -= v[1];
    		v[1] = v[1] * b;
	    	s += v[1];
			doHE ();
			++op;
		}
		ofstream g ("minim2.out");
 		g << op - 1 << '\n';
		return 0;
	}