Here is the problem http://ift.tt/2by4CK8
Here is my solution http://ift.tt/2aZthKJ
int main(){
ofstream fout ("milk2.out");
ifstream fin ("milk2.in");
int n, init, tmp;
int l, s = 0;
fin >> n;
int start[n];
int end[n];
for(lli i = 0; i < n; i++){
fin >> start[i] >> end[i];
}
sort(start, start + n);
sort(end, end + n);
for(int i = 0; i < n; i++){
init = start[0];
if(n == 1){
l = max(l, end[0] - start[0]);
s = 0;
}
else{
if(i == 0){
l = max(l, end[i] - start[i]);
s = 0;
}
else{
if(start[i] > tmp){
init = start[i];
s = max(s, init - tmp);
l = max(l, end[i] - start[i]);
}
else{
l = max(l , end[i] - init);
s = max(s, init - tmp);
}
}
tmp = end[i];
}
}
fout << l << " " << s << endl;
}
Why doesn’t my solution for this problem work, I get the wrong answer for longest milking time in test case 7. Here is the full input data for test case 7 if that is of any use.
Great ask a question on SO and get downvoted for no reason.
Aucun commentaire:
Enregistrer un commentaire