summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-02-13 15:40:42 -0700
committerJack Sangdahl <[email protected]>2025-02-13 15:40:42 -0700
commit644de4dfb5fc7f3e7884621e3dfe5af824c60c30 (patch)
treec705aafea36bd0201a7cf3381c7fd7f111d2e6d5
parentd5c06c689e3328546cd4c486b30a7909651501ed (diff)
downloadcses-644de4dfb5fc7f3e7884621e3dfe5af824c60c30.tar.gz
cses-644de4dfb5fc7f3e7884621e3dfe5af824c60c30.zip
1754. coin piles
-rw-r--r--introductory_problems/coin_piles.cpp12
-rw-r--r--introductory_problems/readme.md7
2 files changed, 19 insertions, 0 deletions
diff --git a/introductory_problems/coin_piles.cpp b/introductory_problems/coin_piles.cpp
new file mode 100644
index 0000000..2d00cc6
--- /dev/null
+++ b/introductory_problems/coin_piles.cpp
@@ -0,0 +1,12 @@
+// 1754. Coin Piles
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ static int t, a, b;
+ scanf("%d", &t);
+ for (int i = 0; i < t; i++) {
+ scanf("%d %d", &a, &b);
+ printf((((a + b) % 3) != 0 || a > 2 * b || b > 2 * a) ? "NO\n" : "YES\n");
+ }
+}
diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md
index 4490312..6b0fb82 100644
--- a/introductory_problems/readme.md
+++ b/introductory_problems/readme.md
@@ -69,3 +69,10 @@ Your task is to calculate the number of trailing zeros in the factorial `n!`. Fo
**Input**: The only input line has an integer `n`. (Example: 20)
**Output**: Print the number of in `n!`. (Example: 4)
+
+### Coin Piles
+You have two coin piles containing `a` and `b` coins. On each move, you can either remove one coin from the left pile and two coins from the right pile, or two coins from the left pile and one coin from the right pile. Your task is to efficiently find out if you can empty both the piles.
+
+**Input**: The first input line has an integer `t`: the number of tests. After this, there are `t` lines, each of which has two integers `a` and `b`: the numbers of coins in the piles. (Example: 3`\n`2 1`\n`2 2`\n`3 3)
+
+**Output**: For each test, print "YES" if you can empty the piles and "NO" otherwise. (Example: YES NO YES)