题目:https://www.luogu.com.cn/problem/P5661
抛出异常:
Exception in thread "main" java.lang.NullPointerException at Main.main(Main.java:11)
代码:
import java.util.*;
public class Main {
public static void main(String [] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner (System.in);
Ticket t[] = new Ticket [100005];
History a[] = new History [100005];
int n=sc.nextInt(),ans=0;
for (int i = 0 ; i < n ; i++) {
a[i].Class=sc.nextInt();
a[i].price=sc.nextInt();
a[i].time=sc.nextInt();
}
for (int i = 0 ; i < n ; i++) {
if (a[i].Class==0) {
t[t.length].price = a[i].price;
t[t.length].time = a[i].time;
}
else {
for (int j = 0 ; j < t.length ; j++) {
if (a[i].time - 45 <= t[j].time && ( a[i].price <= t[j].price && t[j].used==true ) ) {
ans -= a[i].price;
t[j].used = false;
break;
}
}
ans += a[i].price;
}
}
System.out.print(ans);
sc.close();
}
}
class Ticket{
int time=0;
int price=0;
boolean used=true;
}
class History{
int time=0;
int price=0;
int Class=0;
}