You're not signed in!

Sign in to save your progress and sync your settings across devices.

Very Frequent
 0/12

Simulation

Authors: Darren Yao, Allen Li

Directly simulating the problem statement, which many Bronze problems allow you to do.

Resources
IUSACOThis module is based on Chapter 5 of Darren Yao's book

Since there's no formal algorithm involved, the intent of the problem is to assess competence with one's programming language of choice and knowledge of built-in data structures. At least in USACO Bronze, when a problem statement says to find the end result of some process, or to find when something occurs, it's usually sufficient to simulate the process naively.

Example 1

Statement

Alice and Bob are standing on a 2D plane. Alice starts at the point (0,0)(0, 0), and Bob starts at the point (R,S)(R, S) (1R,S10001 \leq R, S \leq 1000). Every second, Alice moves MM units to the right, and NN units up. Every second, Bob moves PP units to the left, and QQ units down. (1M,N,P,Q101 \leq M, N, P, Q \leq 10). Determine if Alice and Bob will ever meet (be at the same point at the same time), and if so, when.

Input Format

The first line of the input contains RR and SS.

The second line of the input contains MM, NN, PP, and QQ.

Output Format

Please output a single integer containing the number of seconds after the start at which Alice and Bob meet. If they never meet, please output 1-1.

Solution

Solution

Example 2

Statement

There are NN buckets (5N1055 \leq N \leq 10^5), each with a certain capacity CiC_i (1Ci1001 \leq C_i \leq 100). One day, after a rainstorm, each bucket is filled with AiA_i units of water (1AiCi1\leq A_i \leq C_i). Charlie then performs the following process: he pours bucket 11 into bucket 22, then bucket 22 into bucket 33, and so on, up until pouring bucket N1N-1 into bucket NN. When Charlie pours bucket BB into bucket B+1B+1, he pours as much as possible until bucket BB is empty or bucket B+1B+1 is full. Find out how much water is in each bucket once Charlie is done pouring.

Input Format

The first line of the input contains NN.

The second line of the input contains the capacities of the buckets, C1,C2,,CNC_1, C_2, \dots, C_N.

The third line of the input contains the amount of water in each bucket A1,A2,,ANA_1, A_2, \dots, A_N.

Output Format

Please print one line of output, containing NN space-separated integers: the final amount of water in each bucket once Charlie is done pouring.

Solution

Solution

Problems

Easier

StatusSourceProblem NameDifficultyTagsSolution
BronzeEasy
Show Tags

Nested Loop

External Sol
BronzeEasy
Show Tags

Single Loop

External Sol
BronzeEasy
Show Tags

Nested Loop

External Sol
BronzeEasy
Show Tags

Single Loop

External Sol
BronzeEasyExternal Sol

Harder

Module Progress:

Give Us Feedback on Simulation!