### You're not signed in!

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

# Simulation

Authors: Darren Yao, Allen Li

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

Resources | |||
---|---|---|---|

IUSACO | This 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)$, and Bob starts at the point $(R, S)$ ($1 \leq R, S \leq 1000$). Every second, Alice moves $M$ units to the right, and $N$ units up. Every second, Bob moves $P$ units to the left, and $Q$ units down. ($1 \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 $R$ and $S$.

The second line of the input contains $M$, $N$, $P$, and $Q$.

#### 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$.

### Solution

Solution

## Example 2

### Statement

There are $N$ buckets ($5 \leq N \leq 10^5$), each with a certain capacity $C_i$ ($1 \leq C_i \leq 100$). One day, after a rainstorm, each bucket is filled with $A_i$ units of water ($1\leq A_i \leq C_i$). Charlie then performs the following process: he pours bucket $1$ into bucket $2$, then bucket $2$ into bucket $3$, and so on, up until pouring bucket $N-1$ into bucket $N$. When Charlie pours bucket $B$ into bucket $B+1$, he pours as much as possible until bucket $B$ is empty or bucket $B+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 $N$.

The second line of the input contains the capacities of the buckets, $C_1, C_2, \dots, C_N$.

The third line of the input contains the amount of water in each bucket $A_1, A_2, \dots, A_N$.

#### Output Format

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

### Solution

Solution

## Problems

### Easier

Status | Source | Problem Name | Difficulty | Tags | Solution |
---|---|---|---|---|---|

Bronze | Easy | ## Show TagsNested Loop | External Sol | ||

Bronze | Easy | ## Show TagsSingle Loop | External Sol | ||

Bronze | Easy | ## Show TagsNested Loop | External Sol | ||

Bronze | Easy | ## Show TagsSingle Loop | External Sol | ||

Bronze | Easy | External Sol |

### Harder

Status | Source | Problem Name | Difficulty | Tags | Solution |
---|---|---|---|---|---|

Bronze | Normal | ||||

Bronze | Normal | ||||

Bronze | Normal | External Sol | |||

Bronze | Normal | ||||

Bronze | Normal | ||||

Bronze | Hard | External Sol | |||

Bronze | Hard |