CodeForces#325 C. Gennady the Dentist

点击就送屠龙宝刀

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

题目大意:有n个熊孩子去看医生,每个人都有一个pi(信心值)、一个vi(声音影响度)、一个di(影响值)。当一个熊孩子接受治疗时,会发出vi的影响,影响后面vi个单位,分别为vi-1,vi-2,vi-3……0.当某个人的信心值pi小于0时,他就吓尿了于是就跑掉了,同时对后面所有人造成di的影响。(注:造成x的影响意思为pi-x)。你的任务就是统计有多少个熊孩子看了医生,并且按照顺序输出他们的编号。

模拟大法好233333毕竟只有4000的范围

#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
const int maxn = 5500;
int v[maxn],p[maxn],d[maxn];


int main()
{
    int n,ans=0;
    scanf("%d",&n);
    vector<int> Q;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&v[i],&d[i],&p[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(p[i]>=0)
        {
        ans++;
        Q.push_back(i);
        for(int j=v[i]-1;j>0;j--)
        {
            p[i+v[i]-j]-=j;
        }

        }
        if(p[i]<0)
        {
            for(int j=i-1;j<=n;j++)
            p[j]-=d[i];
        }
}
    cout<<ans<<endl;
    for(int i=0;i<Q.size();i++) cout<<Q[i]<<" ";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值