Home > Developer > Web Develop

Source: Internet
Author: User

Tags: count freopen color greater than Col double SDFSDF Max def

Title Address: Http://codeforces.com/problemset/problem/1039/A

The key to the problem is to get a clear idea, and then the code is easier to write

For each location of the bus, that is, for each i (i>=1 && i<=n), X[i] must be greater than or equal to I, assuming that the first car can be parked at X[i], for J (J>i && J<=x[i]) to make the car J stop At J-1, that is b[j-1]>=ar[j]+t

If X[x[i]]==x[i], just control let b[x[i]]<ar[x[i]+1]+t

If X[x[i]]!=x[i], then x[x[i]]>x[i], then there must be b[x[i]]>=ar[x[i]+1]+t, let the x[i]+1 car parked in x[i] place, to let X[i] "stop at X[x[i]" place, I can be known, I can also stop in x[ X[i]], in contradiction to test instructions, output no can

#include <iostream>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<string.h>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<fstream>#include<cstdlib>#include<ctime>#include<list>#include<climits>#include<bitset>#include<random>#include<ctime>#include<cassert>#include<complex>#include<cstring>#include<chrono>using namespacestd;#defineFio Ios::sync_with_stdio (false); Cin.tie (0); Cout.tie (0);#definefopen freopen ("input.in", "R", stdin); Freopen ("Output.in", "w", stdout);#defineLeft ASFDASDASDFASDFSDFASFSDFASFDAS1#defineTan Asfdasdasdfasdfasfdfasfsdfasfdasmt19937 rng (Chrono::steady_clock::now (). Time_since_epoch (). Count ()); typedefLong Longll;typedef unsignedintun;Const intdesll[4][2]={{0,1},{0,-1},{1,0},{-1,0}};Const intmod=1e9+7;Const intmaxn=2e5+7;Const intmaxm=1e5+7;Const Doubleeps=1e-4; ll M,n;ll Ar[maxn];ll B[MAXN];intX[MAXN];intMain () {scanf ("%i64d%i64d",&n,&m); for(intI=1; i<=n;i++) scanf ("%i64d",&Ar[i]); for(intI=1; i<=n;i++) scanf ("%d",&X[i]); for(intI=2; i<=n;i++){ if(x[i]<x[i-1] || x[i]<i) {printf ("no\n"); Exit (0); } } intI=1; while(i<=N) {intj=i; while(J<=n && x[j]==X[i]) {J++; } for(intk=i;k<j;k++){ if(x[k]>k) b[k]=ar[k+1]+m; ElseB[k]=max (b[k-1]+1, ar[k]+m); //cout<<k<< "" <<b[k]<<endl; } if(x[j-1]!=j-1|| (J-1<n && b[j-1]>=ar[j]+m)) {printf ("no\n"); Exit (0); } I=J; } printf ("yes\n"); for(LL i=1; i<=n;i++) printf ("%i64d%c", B[i],i==n?'\ n':' '); return 0;}

Codeforces 1039A. Timetable

Related Article