为什么只能过三个啊,已经用了快排

P1478 陶陶摘苹果(升级版)

cfj1291280833 @ 2019-09-03 19:55:56

include<stdio.h>

void quicksort(int a[],int b[],int low,int high){

int i = low;    int j = high;
int tmp = a[low];
int tmp1 = b[low];
if(low < high){
    while(i<j){
        while (j>i && a[j] >= tmp)  j--;
        a[i] = a[j];
        b[i] = b[j];
        while(i<j && a[i] <= tmp)   i++;
        a[j] = a[i];
        b[j] = a[j];
    }
    a[i] = tmp;
    b[i] = tmp1;
    quicksort(a,b,low,i-1);
    quicksort(a,b,i+1,high);
}

}

int main(){

int n,s,a,b;
int i = 0,sum = 0;
int x[5000],y[5000];
scanf("%d %d",&n,&s);
scanf("%d %d",&a,&b);
for(int i = 0; i < n; i++)
    scanf("%d %d",x + i, y + i);
quicksort(y,x,0,n-1);
while(s>0 && i < n){
    if(s-y[i]>=0 && x[i] <= a+b){
        sum++;
        s -= y[i];
    }
    i++;
}
printf("%d",sum);

}


by 只以 @ 2019-09-03 19:56:50

希望更丰富的展现?使用Markdown


by Alex_Wei @ 2019-09-03 19:58:00

希望更丰富的展现?使用Markdown


by pzc2004 @ 2019-09-03 19:58:24

希望更丰富的展现?使用Markdown


by A_Đark_Horcrux @ 2019-09-03 19:59:34

希望更丰富的展现?使用DarkMown


by 小小小朋友 @ 2019-09-03 20:03:54

希望更丰富的展现?使用MarkDown


by 只以 @ 2019-09-03 20:06:59

lz毫无反应。。


by do_while_true @ 2019-09-03 20:07:10

我用冒泡就过了......


by Surelysuper @ 2019-09-03 20:10:11

希望更丰富的展现?使用MarkDown


by _Rainlzy @ 2019-09-03 20:10:17

直接用sort不好吗? @cfj1291280833


|