Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bismillahirrahmanirrahim
- // AgriCoder IPB
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i, agri, coder) for (int i = (int)agri; i <= (int)coder; i++)
- #define REP(agri,coder) for (int agri = 0; agri < (int)coder; agri++)
- #define FOREACH(i,agricoder) for (typeof((agricoder).end()) i = (agricoder).begin(); i != (agricoder).end(); ++i)
- #define RESET(agri,coder) memset(agri, coder, sizeof(agri))
- #define pb push_back
- #define mp make_pair
- #define EPS 1e-9
- #define INF 0x3F3F3F3F
- typedef long long ll;
- typedef pair<int,int> ii;
- typedef vector<int> vi;
- #define MAX (int)(1e+5) + 5
- double d[MAX],d_accu[MAX],t[MAX],v[MAX];
- double ans[MAX];
- int parent[MAX];
- int main() {
- int n,j;
- d_accu[0]=0;
- scanf("%d",&n);
- FOR(i,1,n-1){
- scanf("%lf",&d[i]);
- d_accu[i]=d[i]+d_accu[i-1];
- }
- FOR(i,1,n-1){
- scanf("%lf %lf",&t[i],&v[i]);
- }
- ans[1]=d[1]/v[1]+ t[1];
- parent[1]=0;
- FOR(i,2,n-1){
- ans[i]=t[i]+d_accu[i]/v[i];
- j=i-1;
- double tmp=ans[j]+t[i]+(d_accu[i]-d_accu[j])/v[i];
- if(ans[i]>tmp){
- parent[i]=j;
- ans[i]=tmp;
- }
- for(j=parent[i-1];j>0;j--){
- tmp=ans[j]+t[i]+(d_accu[i]-d_accu[j])/v[i];
- if(ans[i]>tmp){
- parent[i]=j;
- ans[i]=tmp;
- }
- }
- }
- double frac,intpart;
- FOR(i,1,n-1){
- // printf("real: %.5lf, floor: %.5lf, integer: %.0lf\n",ans[i],floor(ans[i]),ans[i]);
- /*
- frac = modf (ans[i] , &intpart);
- if(frac<=0.50000) ans[i]=floor(ans[i]);
- else ans[i]=ceil(ans[i]);
- */ printf("%.0lf\n",ans[i]);
- }
- return 0;
- }
- // Alhamdulillahirabbilalamin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement