Problem #3544 - ECNU Online Judge
#include<bits/stdc++.h>
using namespace std;
typedef struct People{
int score;
int time;
}People;
People people[100001];
bool cmp(People p1,People p2){
return p1.score*p2.time>p1.time*p2.score;
}
int main(){
int n,T,a,t;
cin>>n>>T;
for(int i=1;i<=n;i++){
cin>>people[i].score>>people[i].time;
}
vector<int> dp(T+1);
sort(people+1,people+n+1,cmp);
int ans=0;
for(int i=1;i<=n;i++){
for(int j=T;j>=people[i].time;j--){
dp[j]=max(dp[j],dp[j-people[i].time]+people[i].score*(T-j));
ans=max(ans,dp[j]);
}
}
cout<<ans<<endl;
}