Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.7 kB
1
Indexable
Never
#include <bits/stdc++.h>

using namespace std;
int arra[11];

struct S
{
    char id;
    int ending;
    int duration;
    int payment;
};

bool comp(S item1, S item2)
{
    return ((item1.payment / item1.duration) >= (item2.payment / item2.duration));
}

void fillUp(int arra[], int y, int end)
{
    for (int i = y; i <= end; i++)
        arra[i] = 1;
}

int selecion(S V[], int n, int arra[])
{

    int profit = 0;
    int count = 0;
    int y;

    fillUp(arra, V[0].ending - V[0].duration + 1, V[0].ending);
    profit += V[0].payment;

    cout << V[0].id << endl;

    for (int i = 1; i < n; i++)
    {
        count = 0;
        for (int hour = V[i].ending; hour >= 1; hour--)
        {
            if (arra[hour] == -1)
            {
                count++;

                if (count == V[i].duration)
                {
                    y = hour;
                    break;
                }
            }
        }

        if (count == V[i].duration)
        {
            cout << V[i].id << endl;
            profit += V[i].payment;
            fillUp(arra, y, V[i].ending);
        }
    }
    return profit;
}

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

    S ara[n];
    memset(arra, -1, sizeof(arra));

    for (int i = 0; i < n; i++)
    {
        cout << "task " << i + 1 << ": ";
        cin >> ara[i].id;
        // getchar();
        cin >> ara[i].ending >> ara[i].duration >> ara[i].payment;
    }
    sort(ara, ara + n, comp);

    cout << endl
         << endl;
    for (S x : ara)
        cout << x.id << " " << x.ending << " " << x.duration << " " << x.payment << endl;
    cout << endl
         << endl;

    int X = selecion(ara, n, arra);
    cout << X;
}