Skip to content

Commit e3ab932

Browse files
committed
Add solution for problem B - Coloring
Link: https://codeforces.com/contest/1774/problem/B Tags: constructive algorithms, greedy, math, *1500 Ref: https://codeforces.com/contest/1774/submission/232666220
1 parent 93d901f commit e3ab932

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A repository to keep track of problem solving practice, containing solutions fro
1313

1414
| # | Title | Solution | Tags | Submitted |
1515
|---| ----- | -------- | ---- | --------- |
16+
1102 | [B - Coloring](https://codeforces.com/contest/1774/problem/B) | [GNU C++20 (64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1774/1774B%20Coloring.cpp "GNU C++20 (64)") | `constructive algorithms` `greedy` `math` `*1500` | Nov/13/2023 23:46 |
1617
1101 | [C - Sum on Subarrays](https://codeforces.com/contest/1809/problem/C) | [GNU C++20 (64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1809/1809C%20Sum%20on%20Subarrays.cpp "GNU C++20 (64)") | `constructive algorithms` `greedy` `math` `*1500` | Nov/13/2023 00:34 |
1718
1100 | [E - Price Maximization](https://codeforces.com/contest/1690/problem/E) | [GNU C++20 (64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1690/1690E%20Price%20Maximization.cpp "GNU C++20 (64)") | `binary search` `greedy` `math` `two pointers` `*1500` | Nov/12/2023 19:11 |
1819
1099 | [E - Data Structures Fan](https://codeforces.com/contest/1872/problem/E) | [GNU C++20 (64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1872/1872E%20Data%20Structures%20Fan.cpp "GNU C++20 (64)") | `binary search` `bitmasks` `data structures` `dp` `*1500` | Nov/11/2023 21:10 |

codeforces/1774/1774B Coloring.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
author : MishkatIT
3+
created : Monday 2023-11-13-17.46.30
4+
*/
5+
6+
#include<bits/stdc++.h>
7+
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
8+
#define debug(_) cout << #_ << " is " << _ << '\n';
9+
10+
using namespace std;
11+
using ll = long long;
12+
using ld = long double;
13+
const ll mod = 1e9 + 7;
14+
const ll N = 2e5 + 10;
15+
const ll inf = 1e9;
16+
const ll linf = 1e18;
17+
18+
int main()
19+
{
20+
fio;
21+
int t;
22+
cin >> t;
23+
while (t--) {
24+
ll n, m, k;
25+
cin >> n >> m >> k;
26+
vector<ll> v(m);
27+
for (auto& i : v) {
28+
cin >> i;
29+
}
30+
ll req = (n + k - 1) / k;
31+
int cnt = 0;
32+
ll mx = -1;
33+
for (int i = 0; i < m; i++) {
34+
cnt += (v[i] == req);
35+
mx = max(mx, v[i]);
36+
}
37+
bool ok = true;
38+
if (n % k == 0) {
39+
if (mx > req) {
40+
ok = false;
41+
}
42+
} else {
43+
if (cnt > (n % k) || mx > req) {
44+
ok = false;
45+
}
46+
}
47+
cout << (ok ? "YES" : "NO") << '\n';
48+
}
49+
return 0;
50+
}
51+
52+

submissions.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21853,5 +21853,23 @@
2185321853
"*1500"
2185421854
],
2185521855
"timestamp": "Nov/13/2023 00:34"
21856+
},
21857+
"CF232666220": {
21858+
"contest_id": 1774,
21859+
"language": "GNU C++20 (64)",
21860+
"path": "codeforces\\1774\\1774B Coloring.cpp",
21861+
"platform": "Codeforces",
21862+
"problem_index": "B",
21863+
"problem_name": "Coloring",
21864+
"problem_url": "https://codeforces.com/contest/1774/problem/B",
21865+
"submission_id": "CF232666220",
21866+
"submission_url": "https://codeforces.com/contest/1774/submission/232666220",
21867+
"tags": [
21868+
"constructive algorithms",
21869+
"greedy",
21870+
"math",
21871+
"*1500"
21872+
],
21873+
"timestamp": "Nov/13/2023 23:46"
2185621874
}
2185721875
}

0 commit comments

Comments
 (0)