codeforces 586 C. Gennady the Dentist【Codeforces Round #325 (Div. 2)】

C. Gennady the Dentist

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.

All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in
the order they go in the line. Every child is associated with the value of his cofidence pi.
The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.

While Gennady treats the teeth of the i-th child, the child is crying with the volume of vi.
At that the confidence of the first child in the line is reduced by the amount of vi,
the second one — by value vi - 1,
and so on. The children in the queue after the vi-th
child almost do not hear the crying, so their confidence remains unchanged.

If at any point in time the confidence of the j-th child is less than
zero, he begins to cry with the volume of dj and
leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the j-th
one in the line is reduced by the amount of dj.

All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.

Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 4000)
— the number of kids in the line.

Next n lines contain three integers each vi, di, pi (1 ≤ vi, di, pi ≤ 106)
— the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the i-th
child.

Output

In the first line print number k — the number of children whose teeth Gennady will cure.

In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.

Sample test(s)

input

5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2

output

2
1 3 

input

5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9

output

4
1 2 4 5 

Note

In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children
will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and
run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with
volume 5. The other children won't bear this, and with a loud cry they will run to the exit.

In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be
equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and
run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry
with the volume of 5. The confidences of the remaining children will be equal to 0, 3.
Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1,
and he will go into the office last.

就是一个模拟,也没有什么算法,所以也没啥好说的 。。。

上代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e4+5;
const int mod = 1000000007;
const double eps = 1e-7;
struct node
{
    LL v, d, p;
} arr[maxn];
bool vis[maxn], used[maxn];
int main()
{
    int m;
    scanf("%d",&m);
    for(int i=0; i<m; i++)
        scanf("%d%d%d",&arr[i].v,&arr[i].d,&arr[i].p);
    LL x, y, ret=0;
    MM(vis), MM(used);
    for(int i=0; i<m; i++)
    {
        if(vis[i])
            continue;
        x = arr[i].v, y = 0;
        for(int j=i+1; j<m; j++)
        {
            if(!vis[j])
            {
                arr[j].p -= x;
                x--;
                if(x < 0)
                    break;
            }
        }
        for(int j=i+1; j<m; j++)
        {
            if(!vis[j])
                arr[j].p -= y;
            if(!vis[j] && arr[j].p<0)
            {
                y += arr[j].d;
                vis[j] = 1;
            }
        }
        ret++;
        used[i] = 1;
    }
    cout<<ret<<endl;
    for(int i=0; i<m; i++)
    {
        if(ret == 0)
            break;
        if(used[i])
        {
            used[i] = 0;
            cout<<i+1<<" ";
        }
    }
    cout<<endl;
    return 0;
}
时间: 2024-10-28 18:06:57

codeforces 586 C. Gennady the Dentist【Codeforces Round #325 (Div. 2)】的相关文章

hdu 5499 SDOI 【BestCoder Round #59 (div.2) 】

SDOI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 298    Accepted Submission(s): 117 Problem Description The Annual National Olympic of Information(NOI) will be held.The province of Shando

hdu 5523 Game 【BestCoder Round #61 (div.2)】

Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 315    Accepted Submission(s): 126 Problem Description XY is playing a game:there are N pillar in a row,which numbered from 1 to n.Each pi

Codeforces 591 B Rebranding【Codeforces Round #327 (Div. 2)】

B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebran

Codeforces 400 B. Inna and New Matrix of Candies 【 Codeforces Round #234 (Div. 2)】

B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Can

Codeoforces 558 B. Duff in Love 【 Codeforces Round #326 (Div. 2)】

B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer 

Codeforces 400 C. Inna and Huge Candy Matrix【 Codeforces Round #234 (Div. 2)】

C. Inna and Huge Candy Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! L

Codeforces 400 A. Inna and Choose Options 【Codeforces Round #234 (Div. 2)】

A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusu

Codeforces 407 A. Triangle 【Codeforces Round #239 (Div. 1)】

点击打开链接 A. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the tria

Codeforces 592 A. PawnChess 【Codeforces Round #328 (Div. 2)】

点击打开链接 A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «