-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBessieSlowsDown.cpp
More file actions
92 lines (90 loc) · 1.7 KB
/
BessieSlowsDown.cpp
File metadata and controls
92 lines (90 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
*
* Created by Ziyi Tang
*
*/
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
const int INF = (int)1E9;
const long INFL = (long)1E18;
const int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
#define REP(i,s,t) for(int i=(s);i<(t);i++)
#define FILL(x,v) memset(x,v,sizeof(x))
#define MAXN 1000
#define MOD 1000000007
vector<double> alltime;
vector<double> alldis;
int main(){
freopen("slowdown.in", "r", stdin);
freopen("slowdown.out", "w", stdout);
int n;
cin >> n;
double time = 0.0;
double dis = 0.0;
double co = 1.0;
REP(i,0,n){
char c;
double num;
cin >> c >> num;
if(c == 'T')
alltime.push_back(num);
else
alldis.push_back(num);
}
sort(alltime.begin(), alltime.end());
sort(alldis.begin(), alldis.end());
int pt = 0, pd = 0;
int tsz = alltime.size();
int dsz = alldis.size();
while(pt < tsz && pd < dsz){
double tmpt = alltime[pt];
double tmpd = alldis[pd];
double tmpd_t = time + (tmpd-dis)*co;
if(tmpd_t <= tmpt){
time = tmpd_t;
pd++;
dis = tmpd;
}else{
dis += (tmpt-time)/co;
pt++;
time = tmpt;
}
co++;
}
while(pt != tsz){
dis += (alltime[pt]-time)/co;
time = alltime[pt];
pt++;
co++;
}
while(pd != dsz){
time += (alldis[pd]-dis)*co;
dis = alldis[pd];
co++;
pd++;
}
time += (1000.0-dis)*co;
cout << round(time) << endl;
return 0;
}