Author: @somashekhar001
Tester: @somashekhar001
Editorialist: @somashekhar001
DIFFICULTY:
EASY
PREREQUISITES:
GREEDY
PROBLEM:
you are given duration and deadline of event you have to schedule the events in a order such that you will get maximum reward d-f. ( d is deadline of event given and f is the finishing time of event scheduled by you)
EXPLAINATION :
for maximum reward you have to schedule them in increasing order of their duration.
SOLUTIONS:
#include<bits/stdc++.h>
using namespace std;
class obj{
public:
int a,b;
};
bool compare(obj o1,obj o2){
return o1.a<o2.a;
}
int main()
{
int T;cin>>T;
while(T--)
{
vector<obj>pi;
int n,ans=0;
cin>>n;
while(n--){
int a,b;cin>>a>>b;
pi.push_back({a,b});
}
int start=0;
sort(pi.begin(),pi.end(),compare);
for(auto x:pi){
start=start+x.a;
ans=ans+x.b-start;
}
cout<<ans<<endl;
}
return 0;
}