ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1193. Queue at the Exam

Why WA5? Help!!!
Posted by tester 5 Aug 2009 15:01
This is my program:
#include <stdio.h>

int main ()
{
    int n;
    int mas[100][3] = {};
    bool maska[100] = {};
    int solution = 0;
    int sum = 0;
    int min = 601, k = 0;
    scanf ("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf ("%d%d%d", &mas[i][0], &mas[i][1], &mas[i][2]);
        if (mas[i][0] < min)
        {
            min = mas[i][0];
            k = i;
        }
    }
    sum = mas[k][0];
    maska[k] = 1;
    bool ok = false;
    int exit = 0;
    int save_i = 0;
    while (ok == false)
    {
        min = 9999999;
        sum += mas[k][1];
        maska[k] = 1;
        ok = true;
        if (sum > mas[k][2]) solution += sum - mas[k][2];
        bool key = false;
        exit = k;
        if (k == n - 1) k = -1;
        for (int i = k + 1; i < n; i++)
        {
            if (exit == i) break;
            if (maska[i] == 1) ok = true;
            if ((maska[i] == 0) && (mas[i][0] > sum) && (mas[i][0] < min))
            {
                min = mas[i][0];
                save_i = i;
                key = true;
            }
            if ((maska[i] == 0) && (mas[i][0] <= sum))
            {
                k = i;
                ok = false;
                break;
            }
            if (i == n - 1) i = -1;
        }
        if ((ok == true) && (key == true))
        {
            ok = false;
            k = save_i;
            sum = mas[k][0];
        }
    }
    printf ("%d", solution);

    return 0;
}