結果
| 問題 |
No.2601 Very Poor
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2024-01-13 16:18:00 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 727 bytes |
| コンパイル時間 | 105 ms |
| コンパイル使用メモリ | 29,952 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-09-30 06:34:16 |
| 合計ジャッジ時間 | 1,684 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <stdio.h>
int main () {
int n = 0;
long long x = 0LL;
long long a[400000] = {};
int res = 0;
long long ans = 0LL;
long long tmp = 0LL;
int idx = 0;
res = scanf("%d", &n);
res = scanf("%lld", &x);
for (int i = 0; i < n; i++) {
res = scanf("%lld", a+i);
a[i+n] = a[i];
ans += a[i];
}
if (ans <= x) {
printf("%lld\n", ans);
return 0;
}
ans = 0LL;
for (int i = 0; i < n; i++) {
if (a[i] > x) {
tmp = 0LL;
idx = i+1;
} else {
while (idx < i+n && a[idx]+tmp <= x) {
tmp += a[idx];
idx++;
}
if (tmp > ans) {
ans = tmp;
}
tmp -= a[i];
}
}
printf("%lld\n", ans);
return 0;
}
chro_96