burden 0f love

mail@pastecode.io avatar
unknown
plain_text
7 months ago
889 B
5
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
int pay(int start, int money, int eventnum, int event[]) //計算經歷事件數
{
    int count = 0;
    for (int i = start; i < eventnum; i++)
    {
        if (money >= event[i])
        {
            money -= event[i];
            count++;
        }
        else
        {
            break;
        }
    }
    printf("%d\n", count);
    return 0;
}

int main()
{   
    int eventnum;
    scanf("%d", &eventnum);
    int *event = (int*)malloc(sizeof(int) * eventnum);
    for (int i = 0; i < eventnum; i++)
    {
        scanf("%d", &event[i]);
    }
    
    int question;
    scanf("%d", &question);

    while (question != 0)
    {
        int start, money;
        scanf("%d%d", &start, &money);
        pay(start, money, eventnum, event);
        question--;
    }
    free(event);
    return 0;
}
Leave a Comment