Codeforces Gennady The Dentist Solution in Java

import java.io.*;
public class Gennadythedentist
{

public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int count=0;
        String cds="";
        long dd=0;
        long var[]=new long[n];
        long dar[]=new long[n];
        long par[]=new long[n];
        int flag[]=new int[n];
        int i;
        for(i=0;i<n;i++)
{
String val[]=br.readLine().split(" ");
var[i]=Integer.parseInt(val[0]);
dar[i]=Integer.parseInt(val[1]);
par[i]=Integer.parseInt(val[2]);
flag[i]=0;
}
for(i=0;i<n;i++)
{
if(par[i]<0)
continue;

count++;
dd=0;
cds +=String.valueOf((i+1));
int j=i+1;
while(j<n )
{
flag[j]=0;
if(par[j]>=0 ){
flag[j]=1;
if(var[i]>0)
{
par[j]-=var[i];

}
var[i]--;
}

j++;

}
j=i+1;
while(j<n)
{
if(par[i]>=0)
{
par[j]-=dd;
}

if(par[j]<0 && flag[j]==1)
{ dd+=dar[j];
}

j++;

}

if(i!=n-1)
cds+=" ";
}
System.out.println(count);
System.out.println(cds);

}

}

Comments

  1. Coin Casino: 100% Up To $1600 Bonus + 100 Free Spins
    The only casino in the US febcasino that offers Bitcoin 인카지노 bonus, Coin Casino has hundreds of games like slots, 바카라 bingo, blackjack, roulette, live dealer, video poker,

    ReplyDelete

Post a Comment

Popular Posts