結果
| 問題 |
No.2601 Very Poor
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2024-01-12 22:45:45 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,185 bytes |
| コンパイル時間 | 14,971 ms |
| コンパイル使用メモリ | 378,004 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-09-27 23:29:34 |
| 合計ジャッジ時間 | 14,006 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 2 |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:19:9 | 19 | let mut a: Vec<usize> = input | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
use std::collections::VecDeque;
use std::io;
use std::str::FromStr;
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let parts: Vec<usize> = input
.trim()
.split_whitespace()
.map(|x| usize::from_str(x).unwrap())
.collect();
let n = parts[0];
let _x = parts[1];
input.clear();
io::stdin().read_line(&mut input).unwrap();
let mut a: Vec<usize> = input
.trim()
.split_whitespace()
.map(|x| usize::from_str(x).unwrap())
.collect();
// Aを連結する
let mut extended_a = a.clone();
extended_a.extend(a);
// Dequeの作成
let mut deque = VecDeque::new();
let mut total = 0;
let mut ans = 0;
for &item in &extended_a {
deque.push_back(item);
total += item;
// 合計がxを超えたら先頭から要素を取り出す
while total > _x && deque.len() <= n{
if let Some(front) = deque.pop_front() {
total -= front;
}
}
ans = std::cmp::max(ans,total);
}
// 最終的なDequeの内容を表示
println!("{}", ans);
}
H20