_EugeneLiu 2017-09-14 16:23 采纳率: 0%
浏览 824

CF中第12个测验运行时错误

以下是题目内容:
Another semester has ended and Arthur finally achieved his dream of attending Data Structures I with all professors in the Mathematics Department. Now, he can finally pass this subject, but, like everyone expected, he didn't do any PAs (programming assignments), and all deadlines have passed.

Fortunately, all PAs can still be submitted for grading, but with a penalty given by: (late submission time) - (expected deadline time) for each PA.

Arthur, having taken Data Structures I so many times, knows exactly how much time he needs to complete each assignment. Now, he wants to write a program that determines the minimum sum of penalties that can be achieved, given he can do the PAs in any order.

It's worth noting that Arthur can't do more than one assignment at a time, since that skill is only learned in Data Structures II. Therefore, if Arthur starts working on an assignment, he needs to finish it before starting any other.

There is only one problem left: Arthur believes this problem to be unsettlingly similar to a PA, and, therefore, refuses to do it.

Help Arthur complete this task and, finally, take Data Structures II.

Input
The first line of input contains two integers 1 ≤ n ≤ 105 and 1 ≤ s ≤ 109, the amount of PAs Arthur needs to do and the time when he started to do them, respectively.

n lines follow, the i-th line contains two integers 1 ≤ ti ≤ 109 and 0 ≤ ei ≤ 109, the time Arthur takes to complete the i-th assignment and the expected deadline time for that assignment.

It is guaranteed s > ei for all i.

Output
Print the sum of all penalties if Arthur completes the PAs in the optimal order.
下面是我的代码:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

public static void main(String[] args)
{
    class Task
    {
        long l1;
        long l2;
        public Task(long l1,long l2)
        {
            this.l1=l1;
            this.l2=l2;
        }
    }
    Scanner s=new Scanner(System.in);
    int a;long b;
    a=s.nextInt();b=s.nextLong();
    //long aa[][]=new long[a][2];
    ArrayList<Task> al=new ArrayList<Task>();
    long input1,input2;
    for(int i=0;i<a;i++)
    {
        input1=s.nextLong();
        input2=s.nextLong();
    //    aa[i][0]=input1;
      //  aa[i][1]=input2;
        al.add(new Task(input1,input2));
    }
    /*for(int i=0;i<a-1;i++)
        for(int j=0;j<a-i-1;j++)
        {
            if(aa[j][0]>aa[j+1][0])
            {
                long temp1,temp2;
                temp1=aa[j+1][0];temp2=aa[j+1][1];
                aa[j+1][0]=aa[j][0];aa[j+1][1]=aa[j+1][1];
                aa[j][0]=temp1;aa[j][1]=temp2;
            }
        }*/
    Collections.sort(al,new Comparator<Task>()
    {
         public int compare(Task p1,Task p2)
         {
              return p1.l1<p2.l1?-1:1;
         }
    });

    long sum=b;
    long sum1=0L;

/* for(int i=0;i<a;i++)
{
sum+=aa[i][0];
sum1+=sum-aa[i][1];
}*/
/* for(int i=0;i<a;i++)
{
System.out.println(al.get(i).l1+" "+al.get(i).l2);
}*/
for(int i=0;i<a;i++)
{
sum+=al.get(i).l1;
sum1+=sum-al.get(i).l2;
}
/* for(int i=0;i<a;i++)
{
System.out.println(al.get(i).l1+" "+al.get(i).l2);
}*/
System.out.println(sum1);
}
}

  • 写回答

1条回答

  • devmiao 2017-09-15 01:04
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计