CCF|公共钥匙盒|Java

时间:2024-09-08 20:36:20

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

int N = in.nextInt();

int K = in.nextInt();

int[] g = new int[N];

int[] w = new int[K];

int[] s = new int[K];

int[] c = new int[K];

    for (int i = 1; i <= N; i++)
{
g[i - 1] = i;
} int tt = 0;
for (int i = 0; i < K; i++)
{ w[i] = in.nextInt();
s[i] = in.nextInt();
c[i] = in.nextInt();
if(c[i]+s[i]>tt)
{
tt=c[i]+s[i];
}
}
int t=0;
while (t<tt)
{
t++; for(int i=0;i<K;i++)
{
if(s[i]==t)
{
if(check(g,w[i])!=-1)
{
for(int k=0;k<N;k++)
{
if(g[k]==w[i])
{
g[k]=0;
}
}
}
}
if(t==(s[i]+c[i]))
{
re(g,w[i]);
}
} }
for(int i=0;i<N;i++)
{
System.out.print(g[i]+" ");
}
}
private static void re(int[] ints,int v)
{
for(int i=0;i<ints.length;i++)
{
if(ints[i]==0)
{
ints[i]=v;
return;
}
}
}
private static int check(int[] ints,int v)
{
int r=-1;
for(int i=0;i<ints.length;i++)
{
if(v==ints[i])
{
r=i;
break;
}
}
return r;
}

}