Pagini recente » Cod sursa (job #2711153) | Cod sursa (job #1611072) | Cod sursa (job #1855420) | Cod sursa (job #816281) | Cod sursa (job #906227)
Cod sursa(job #906227)
#include <fstream>
#include <algorithm>
#define nmax 100100
using namespace std;
int N,M,Capacitate[nmax],Timp[nmax];
int AnswerA,AnswerB,V[nmax];
bool Solution(int Val) {
int i,Sum=0;
for(i=1;i<=N;i++)
Sum+=(Val/Timp[i])*Capacitate[i];
return (Sum>=M);
}
int BinarySearch() {
int i,Step;
Step=(1LL<<25);
for(i=0;Step;Step>>=1)
if(!Solution(i+Step))
i+=Step;
return (i+1);
}
void solve() {
AnswerA=BinarySearch();
for(int i=1;i<=N;i++)
V[i]=(AnswerA/Timp[i])*Capacitate[i];
sort(V+1,V+N+1);
reverse(V+1,V+N+1);
for(int Sum=0;Sum<M;AnswerB++)
Sum+=V[AnswerB+1];
}
void read() {
ifstream in("garaj.in");
in>>N>>M;
for(int i=1;i<=N;i++) {
in>>Capacitate[i]>>Timp[i];
Timp[i]<<=1;
}
in.close();
}
void write() {
ofstream out("garaj.out");
out<<AnswerA<<' '<<AnswerB<<'\n';
out.close();
}
int main() {
read();
solve();
write();
return 0;
}