NCU_KOSUKESHI @ 2019-01-12 13:30:24
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int n,s;//苹果数、力气
int chair, hand;
int court=0;
int number(int p[10010], int q[10010]);
int high[10010],F[10010];
int main() {
scanf("%d%d\n", &n, &s);
scanf("%d%d\n", &chair, &hand);
for(int i=1;i<=n;i++)
{
cin>>high[i]>>F[i];
}
printf("%d\n",number(high,F));
return 0;
}
int number(int p[10010], int q[10010])
{
int f[n];
int fn = 0;
int sum = 0;
for(int i=1;i<=n;i++)
{
if(hand + chair >= p[i])
{
f[fn] = q[i];
fn++;
}
}
for(int i = 1;i<fn;i++)
{
for (int j = 1; j <= fn - i; j++)
{
if (f[j] > f[j + 1]) {
int t = f[j];
f[j] = f[j + 1];
f[j + 1] = t;
}
}
}
for(int i = 1;i<=fn;i++)
{
sum += f[i];
if(sum>s) break;
else court++;
}
return court;
}
by AuCloud @ 2019-01-12 14:09:50
int f[n];
int fn = 0;
int sum = 0;
for(int i=1;i<=n;i++)
{
if(hand + chair >= p[i])
{
f[fn] = q[i];
fn++;
}
}
这里是从0开始的,
但是
for(int i = 1;i<fn;i++)
{
for (int j = 1; j <= fn - i; j++)
{
if (f[j] > f[j + 1]) {
int t = f[j];
f[j] = f[j + 1];
f[j + 1] = t;
}
}
}
for(int i = 1;i<=fn;i++)
{
sum += f[i];
if(sum>s) break;
else court++;
}
这里是从1开始的
by AuCloud @ 2019-01-12 14:11:36
嗯是的亲测有效
(不会被棕吧)