結果

問題 No.2601 Very Poor
コンテスト
ユーザー heno239
提出日時 2024-02-05 17:35:35
言語 C#
(.NET 10.0.201)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,212 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,272 ms
コンパイル使用メモリ 171,312 KB
実行使用メモリ 197,420 KB
最終ジャッジ日時 2026-04-16 11:41:31
合計ジャッジ時間 11,959 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (86 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

internal class Program
{
    private const long mod = 998244353;

    
    public static void Main(string[] args)
    {
        int[] line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int n = line[0];
        int x = line[1];
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        long sum = 0;
        for (int i = 0; i < n; i++) sum += a[i];
        if (sum <= x)
        {
            Console.WriteLine(sum);
            return;
        }

        int r = 0;
        sum = 0;
        long ans = 0;
        for (int l = 0; l < n; l++)
        {
            while (sum + a[r] <= x)
            {
                sum += a[r];
                r++;
                if (r == n) r = 0;
            }
            //Console.WriteLine("{0},{1}",l,sum);
            ans = Math.Max(ans, sum);
            sum -= a[l];
        }
        Console.WriteLine(ans);
    }

    public static List<int> mkar(int n, int val)
    {
        List<int> res = new List<int>(n);
        for(int i=0;i<n;i++)res.Add(val);
        return res;
    }
}
0