題目是這樣的:有N個任務要完成,每個任務都有一個時限,和完成這個任務所需要的時間。如果完成時的時間超過了時限,就要懲罰跟超過的時間相同的分數。若使罰分中的最大值最小,這個最小值是多少?
做完才發現有點像DP。。
先把這些任務按 deadline 排序,然後用方程以此求出即可。
f [ i ] = max (f [ i - 1], cost[1 to i] - deadline [ i ] )
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef struct {
__int64 cost;
__int64 dl;
} TASK;
bool cmp(TASK a, TASK b){
return a.dl < b.dl;
}
TASK input[100000];
int main(){
int T, caseNo = 0;
scanf("%d", &T);
while(T--){
int N;
__int64 costTotal = 0, time = 0, penalty = 0;
scanf("%d", &N);
for(int i = 0; i < N; i++)
scanf("%l64d %l64d", &input[i].cost, &input[i].dl);
sort(input, input + N, cmp);
__int64 MAX = 0;
for(int i = 0; i < N; i++){
time += input[i].cost;
__int64 temp = time - input[i].dl;
if(temp > MAX)
MAX = temp;
}
cout << "Case " << ++caseNo << ": " << MAX << endl;
}
}