Description
2
T 30
D 10
2970
Hint
by hansang:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e4+10;
double t[N], d[N];
int main(){
int n; scanf("%d", &n);
int len1=0, len2=0;
for(int i=1; i<=n; i++){
char s[5]; double x;
scanf("%s%lf", s, &x);
if(s[0]=='T') t[++len1]=x;
else d[++len2]=x;
}
sort(t+1, t+len1+1); sort(d+1, d+len2+1);
double tmp=0, dis=0, sum=1; int p1=1, p2=1;
while(p1<=len1 || p2<=len2){
if((p2>len2) || ((t[p1]-tmp)<(d[p2]-dis)*sum && p1<=len1)){
dis+=(t[p1]-tmp)/sum;
tmp=t[p1]; p1++;
}
else{
tmp+=(d[p2]-dis)*sum;
dis=d[p2]; p2++;
}
sum++;
}
printf("%.0lf\n", tmp+(1000-dis)*(sum));
return 0;
}