C过了,但是有个小问题

P1478 陶陶摘苹果(升级版)

XXXtentation @ 2019-10-24 18:47:26

#include<stdio.h>
int main()
{
    int s, n, a, b, c, p[5050][2] = { 0 }, q[5050] = { 0 }, x = 0, y = 0, g = 0;
    scanf("%d %d", &n, &s); int m = n; int o = 0;
    scanf("%d %d", &a, &b); c = a + b;
    for (n; n >0; --n)
    {
        scanf("%d %d", &p[x][1], &p[x][2]);
        if (p[x][1]<= c)
        {
            q[o] = p[x][2];
            o++;
        }
    }
    for (int u =0; u < o-1; u++)
    {
        for (int j = 0; j < o-1 - u; j++)
        {
            if (q[j] <= q[j + 1])
            {
                int r = q[j];
                q[j] = q[j + 1];
                q[j + 1] = r;
            }
        }
    }
    for (o; o >= 0; o--)
    {
        s -= q[o];
        if (s < 0) break;
        else g++;
    }
    printf("%d", g-1 );
    return 0;

}

最后输出的时候,我本来是打算输出g,但是总是0分,然后输出g-1,就过了 ,不知道怎么过的 好奇怪


|