660B - Seating On Bus - CodeForces Solution


implementation *1000

Please click on ads to support us..

Python Code:

nm = [int(el) for el in input().split()]
n,m = nm[0],nm[1]

f1 = [0 for _ in range(n)]
f2 = [0 for _ in range(n)]
f3 = [0 for _ in range(n)]
f4 = [0 for _ in range(n)]

ctd = 1

ix = 0
while ix < n:
    if ctd > m:
        break

    if f1[ix] == 0:
        f1[ix] = ctd
        ctd += 1
    elif f4[ix] == 0:
        f4[ix] = ctd
        ctd += 1
    else:
        ix += 1

ix = 0
while ix < n:
    if ctd > m:
        break

    if f2[ix] == 0:
        f2[ix] = ctd
        ctd += 1
    elif f3[ix] == 0:
        f3[ix] = ctd
        ctd += 1
    else:
        ix += 1

ctd = m
strRes = ""

i = 0
while ctd > 0:
    if i >= n:
        break

    if not f2[i] == 0:
        strRes += f' {f2[i]}'
        f2[i] = 0
        ctd -= 1
    elif not f1[i] == 0:
        strRes += f' {f1[i]}'
        f1[i] = 0
        ctd -= 1
    elif not f3[i] == 0:
        strRes += f' {f3[i]}'
        f3[i] = 0
        ctd -= 1
    elif not f4[i] == 0:
        strRes += f' {f4[i]}'
        f4[i] = 0
        ctd -= 1
    else:
        i += 1

print(strRes.lstrip())
  		  	   						  	 			 	 				

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int a[110][7]; 
void solve(std::istream &in, std::ostream &out){
    int n,m,j=-1,k=0; in>>n>>m; 
    for(int i=0;i<108;i++) for(int q=0;q<6;q++) a[i][q]=0;
    for(int i=1;i<=n;i++){
    	j+=2;
    	if(j>m) break;
    	a[i][1]=j;
	}
	for(int i=1;i<=n;i++){
    	k+=2;
    	if(k>m) break;
    	a[i][4]=k;
	}
	int r=min(j,k),s=max(j,k);
	for(int i=1;i<=n;i++){
    	r+=2;
    	if(r>m) break;
    	a[i][2]=r;
	}
	for(int i=1;i<=n;i++){
    	s+=2;
    	if(s>m) break;
    	a[i][3]=s;
	}
	j=1;
	int order[]={2,1,3,4};
	for(int i=1;i<=n;i++){
		for(int q=0;q<4;q++){
			if(a[i][order[q]]){
				out<<a[i][order[q]]<<" ";
				j++;
				if(j>m) return;
			}
		}
	}
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int tc=1; 
	while(tc--) solve(std::cin, std::cout);
    return 0;
}
/*
	Holy codeforces,
	let me AC!
*/

/*  printf("                                                                          \n");
	printf("                                                                           \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *        *        \n");
	printf("            *           *         *                *                *      \n");
	printf("           *            *         *               *               *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                    *            \n");
	printf("        *               *         *           *                      *            \n");
	printf("      *                  *       *          *                *      *              \n");
	printf("    * * * * * * *          * * *          * * * * * * *        * * *   \n");                      \n");
*/    


Comments

Submit
0 Comments
More Questions

1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry