_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 ROS Turtlebot3 多机协同自主探索环境时遇到的多机任务分配问题,explore节点
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题