Răspuns :
#include <fstream>
#include<algorithm>
using namespace std;
ifstream fin("maraton.in");
ofstream fout("maraton.out");
int main()
{
int a[100001], n, q, mr, v, p;
fin >> n;
for(int i = 1; i <= n; ++i){
fin >> mr >> v;
if(mr % v == 0)
a[i] = mr / v;
else
a[i] = mr / v + 1;
}
sort(a + 1, a + n + 1);
fin >> q;
for(int i = 1; i <= q; ++i){
int x;
fin >> x;
if(a[n] <= x)
fout << n << '\n';
else if(a[1] > x)
fout << 0 << '\n';
else{
int st = 1, dr = n, p;
while(st <= dr){
int mij = (st + dr) / 2;
if(a[mij] <= x){
p = mij;
st = mij + 1;
}
else
dr = mij - 1;
}
fout << p << '\n';
}
}
return 0;
}
Am folosit cautarea binara pentru a rezolva aceasta problema.
mr = metri ramasi
v = viteza
Daca ai nelamuriri, ma poti intreba!
P.S. A luat 100 de pct. pe PbInfo.