• MaratonIME does (not do) PAs 【罚时】


    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 ≤ t i ≤ 109 and 0 ≤ e i ≤ 109, the time Arthur takes to complete the i-th assignment and the expected deadline time for that assignment.

    It is guaranteed s > e i for all i.

    Output

    Print the sum of all penalties if Arthur completes the PAs in the optimal order.

    Example

    Input
    2 1
    2 0
    1 0
    Output
    6

    Note

    In the first example, if Arthur does the second PA first, he finishes it at time 2, and finishes the first one at time 4, making his total penalty equals to (2-0)+(4-0) = 6.

    ————————————————————————————

    非常恐怖,兄弟

    就这么一道没有任何技巧的题我确确实实做不出来了

    还是以前没真正理解罚时是怎么算的

    暗搓搓去看别人代码了...

    e 和 t 范围是<=10^9还是要用long long int


    ————————————————————————————

    #include <bits/stdc++.h>
    
    using namespace std;
    struct node{
        long long int t;
        long long int e;
    }a[100100];
    
    bool cmp(node q, node w){
        if(q.t != w.t)
            return q.t < w.t;
        else
            return q.e < w.e;
    }
    
    int main()
    {
        long long int n, s;
        scanf("%lld%lld", &n, &s);
        for(int i = 0; i<n; i++){
            scanf("%lld%lld", &a[i].t, &a[i].e);
        }
        sort(a, a+n, cmp);      //排下序,用时少的在前边
        long long int sum = 0, k;
        for(int i = 0; i<n; i++){
            k = s - a[i].e + a[i].t;    // s-a[i].e现在的时间减去该题截止时间,加上a[i].t做题所需时间
            sum += k;                //sum是罚时总和
            s += a[i].t;              //s是现在的时间
        }
        printf("%lld
    ", sum);
        return 0;
    }
  • 相关阅读:
    3.3 直方图处理与函数绘图
    光头强
    考试代码模板
    【2015初赛】预备
    NOIP2018 模拟题
    NOIP2017 模拟赛
    【解题报告】树形DP入门
    【解题报告】区间DP
    【解题报告】树形背包
    二分刷题单
  • 原文地址:https://www.cnblogs.com/kaito77/p/12870421.html
Copyright © 2020-2023  润新知