#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
struct fuck
{
ll a, b, c;
double d;
};
struct fucky
{
ll f, g, h;
};
int main()
{
ll n, x, y, i, j, k = 0, t, w;
while(cin >> x >> y)
{
cin >> n;
vector<fuck>r;
for(i=1;i<=n;i++)
{
cin >> t >> w;
double o = (double)w/(double)t;
r.push_back({t, w, i, o});
}
int s = r.size();
for(i=0;i<s-1;i++)
{
for(j=0;j<s-i-1;j++)
{
if(r[j].d < r[j+1].d)
{
swap(r[j].a, r[j+1].a);
swap(r[j].b, r[j+1].b);
swap(r[j].c, r[j+1].c);
swap(r[j].d, r[j+1].d);
}
}
}
ll p, q, counts = 0, m = 0, mark = 0;
vector<fucky>u;
for(i=0;i<s;i++)
{
p = r[i].a;
q = (p*y) +(2*y*p);
if(x>=m+q)
{
mark += r[i].b;
m += q;
counts++;
u.push_back({r[i].a, r[i].b, r[i].c});
}
else
break;
}
s = u.size();
for(i=0;i<s-1;i++)
{
for(j=0;j<s-i-1;j++)
{
if(u[j].h > u[j+1].h)
{
swap(u[j].f, u[j+1].f);
swap(u[j].g, u[j+1].g);
swap(u[j].h, u[j+1].h);
}
}
}
if(k > 0)
cout << endl;
cout << mark << endl << counts << endl;
for(i=0;i<s;i++)
{
cout << u[i].f << " " << u[i].g << endl;
}
r.clear();
u.clear();
k++;
}
return 0;
}
#define ll unsigned long long int
using namespace std;
struct fuck
{
ll a, b, c;
double d;
};
struct fucky
{
ll f, g, h;
};
int main()
{
ll n, x, y, i, j, k = 0, t, w;
while(cin >> x >> y)
{
cin >> n;
vector<fuck>r;
for(i=1;i<=n;i++)
{
cin >> t >> w;
double o = (double)w/(double)t;
r.push_back({t, w, i, o});
}
int s = r.size();
for(i=0;i<s-1;i++)
{
for(j=0;j<s-i-1;j++)
{
if(r[j].d < r[j+1].d)
{
swap(r[j].a, r[j+1].a);
swap(r[j].b, r[j+1].b);
swap(r[j].c, r[j+1].c);
swap(r[j].d, r[j+1].d);
}
}
}
ll p, q, counts = 0, m = 0, mark = 0;
vector<fucky>u;
for(i=0;i<s;i++)
{
p = r[i].a;
q = (p*y) +(2*y*p);
if(x>=m+q)
{
mark += r[i].b;
m += q;
counts++;
u.push_back({r[i].a, r[i].b, r[i].c});
}
else
break;
}
s = u.size();
for(i=0;i<s-1;i++)
{
for(j=0;j<s-i-1;j++)
{
if(u[j].h > u[j+1].h)
{
swap(u[j].f, u[j+1].f);
swap(u[j].g, u[j+1].g);
swap(u[j].h, u[j+1].h);
}
}
}
if(k > 0)
cout << endl;
cout << mark << endl << counts << endl;
for(i=0;i<s;i++)
{
cout << u[i].f << " " << u[i].g << endl;
}
r.clear();
u.clear();
k++;
}
return 0;
}
Comments
Post a Comment