Failed to execute the Problem Bags (Guloso | D) - CodeCad

0

Hello, I'm trying to do an exercise in CodCad called Pouches, where I need to use greedy algorithms. Link: link

I have tested several types of input and all have hit the exit of my program, I need help to know where the error is and because my program only hits 20% of CodCad tests.

My C ++ program:

#include <iostream>
#include <algorithm>

#define MAXN 10000
using namespace std;

struct Pedidos
{
    int tempo,prazo;
};

bool ordem(Pedidos a, Pedidos b)
{
    return a.prazo < b.prazo;
}

int main()
{
    int n,i;
    cin >> n;

    Pedidos pedido[MAXN];
    for(i=0; i<n ; i++){cin >> pedido[i].tempo >> pedido[i].prazo;}
    sort(pedido,pedido+n,ordem);

    int inicio=0;
    short int ans=0,aux=0;
    for(i=0; i<n ; i++)
    {
        aux = (inicio + pedido[i].tempo) - pedido[i].prazo;
        if(aux > ans){ans = aux;}

        inicio += pedido[i].tempo;
    }

    cout << ans << endl;

    return 0;
}
    
asked by anonymous 13.06.2018 / 02:47

0 answers