_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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站