Codeforces 1039A. Timetable

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.