Skip to content

Commit 97f555d

Browse files
committed
Add an example for ABC160-E
1 parent 63f6d91 commit 97f555d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

examples/abc160-e.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// https://atcoder.jp/contests/abc160/tasks/abc160_e
2+
//
3+
// 以下のクレートを使用。
4+
// - `itertools`
5+
// - `proconio`
6+
7+
use itertools::Itertools as _;
8+
use proconio::input;
9+
10+
use std::cmp::{self, Reverse};
11+
12+
fn main() {
13+
// `proconio::input!`はオリジナルの`input!`とは違い、`mut $ident`の形式で入力を読むことができる。
14+
//
15+
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
16+
input! {
17+
x: usize,
18+
y: usize,
19+
a: usize,
20+
b: usize,
21+
c: usize,
22+
mut ps: [u64; a],
23+
mut qs: [u64; b],
24+
mut rs: [u64; c],
25+
}
26+
27+
ps.sort_unstable_by_key(|&p| Reverse(p));
28+
qs.sort_unstable_by_key(|&q| Reverse(q));
29+
rs.sort_unstable_by_key(|&r| Reverse(r));
30+
31+
// `itertools::Itertools::kmerge_by`で降順のままでマージする。
32+
//
33+
// https://docs.rs/itertools/0.9/itertools/trait.Itertools.html#method.kmerge_by
34+
let ans = vec![&ps[..x], &qs[..y], &rs[..cmp::min(x + y, c)]]
35+
.into_iter()
36+
.kmerge_by(|v1, v2| v1 > v2)
37+
.take(x + y)
38+
.sum::<u64>();
39+
println!("{}", ans);
40+
}

test-examples.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ url = "https://atcoder.jp/contests/abc157/tasks/abc157_e"
219219
matching = "Words"
220220
meta = { using = ["alga", "proconio", "whiteread"] }
221221

222+
[examples.abc160-e]
223+
type = "Normal"
224+
name = "ABC160: E - Red and Green Apples"
225+
url = "https://atcoder.jp/contests/abc160/tasks/abc160_e"
226+
matching = "Words"
227+
meta = { using = ["itertools", "proconio"] }
228+
222229
[examples.agc023-a]
223230
type = "Normal"
224231
name = "AGC023: A - Zero-Sum Ranges"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy