Codeforces 586C Gennady the Dentist【模拟】

来源:互联网 发布:mac os 光盘镜像 编辑:程序博客网 时间:2024/05/17 05:03

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 from1 ton in the order they go in the line. Every child is associated with the value of hiscofidencepi. 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 ofvi. At that theconfidence of the first child in the line is reduced by the amount ofvi, the second one — by valuevi - 1, and so on. The children in the queue after thevi-th child almost do not hear the crying, so theirconfidence remains unchanged.

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

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 eachvi, 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 theconfidence of thei-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.

Examples
Input
54 2 24 1 25 2 43 3 55 1 2
Output
21 3 
Input
54 5 15 3 94 1 22 1 84 1 9
Output
41 2 4 5 
Note

In the first example, Gennady first treats the teeth of the first child who will cry with volume4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of1 and run to the exit. The confidence of the remaining children will be equal to0, 2, 0. Then the third child will go to the office, and cry with volume5. 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 volume4. The confidence of the remaining children will be equal to5,  - 1, 6, 8. Thus, the third child will cry with the volume of1 and run to the exit. The confidence of the remaining children will be equal to5, 5, 7. After that, the second child goes to the office and cry with the volume of5. The confidences of the remaining children will be equal to0, 3. Then the fourth child will go into the office and cry with the volume of2. Because of this the confidence of the fifth child will be1, and he will go into the office last.


题目大意:

现在有N个小孩在排队看医生,每个人有三个元素:v,d,p。其中p代表每个小孩的勇气值,如果勇气值小于0的时候,这个小孩就会逃跑,并且对其身后所有的小孩的勇气值造成d的伤害值。

小孩按照顺序进入医疗室,当进入的时候,他一共会哭出来V单位的眼泪,后边的小孩会受到影响,他身后第一个小孩的勇气值会减少v,第二个小孩的勇气值会减少v-1.第三个小孩的勇气值会减少v-2.当按照这个规律到v-v的时候,之后的小孩就不会受影响。

问哪些小孩会成功的被医疗。


思路:


因为N并不大,所以我们O(n^2)模拟即可。

不过注意一点,在模拟过程中,一定要按照情景进行模拟,其中有一些限制顺序存在互相影响的关系。


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;#define ll __int64struct node{    ll v,d,p;}a[5000];int vis[5000];int ans[5000];int n;void Slove(int pos){    vis[pos]=1;    for(int i=pos+1;i<n;i++)    {        if(vis[i]==1)continue;        a[i].p-=a[pos].d;    }    for(int i=pos+1;i<n;i++)    {        if(vis[i]==0&&a[i].p<0)Slove(i);    }}int main(){    while(~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        for(int i=0;i<n;i++)        {            scanf("%I64d%I64d%I64d",&a[i].v,&a[i].d,&a[i].p);        }        int cont=0;        for(int i=0;i<n;i++)        {            if(vis[i]==1)continue;            if(a[i].p>=0)            {                ans[cont++]=i+1;                for(int j=i+1;j<n;j++)                {                    if(vis[j]==1)continue;                    if(a[i].v>0)                    {                        a[j].p-=a[i].v;                        a[i].v-=1;                    }                }                for(int j=i+1;j<n;j++)                {                    if(a[j].p<0&&vis[j]==0)                    {                        Slove(j);                    }                }            }            else Slove(i);        }        printf("%d\n",cont);        for(int i=0;i<cont;i++)printf("%d ",ans[i]);        printf("\n");    }}



0 0
原创粉丝点击