結果

問題 No.1430 Coup de Coupon
ユーザー さかぽんさかぽん
提出日時 2021-03-14 18:02:59
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,774 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 109,696 KB
実行使用メモリ 29,676 KB
最終ジャッジ日時 2024-04-24 01:00:24
合計ジャッジ時間 3,012 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
25,672 KB
testcase_01 AC 40 ms
25,864 KB
testcase_02 AC 37 ms
25,520 KB
testcase_03 AC 40 ms
25,844 KB
testcase_04 AC 42 ms
25,744 KB
testcase_05 AC 42 ms
25,488 KB
testcase_06 AC 46 ms
25,844 KB
testcase_07 AC 49 ms
25,988 KB
testcase_08 AC 47 ms
25,972 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 48 ms
27,692 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 39 ms
25,752 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class B
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int t, int x) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var (n, cc) = Read2();
		var ps = Array.ConvertAll(new bool[n], _ => int.Parse(Console.ReadLine()));
		var cs = Array.ConvertAll(new bool[cc], _ => Read2());

		ps = ps.OrderBy(x => -x).ToArray();
		//var q1 = new Queue<int>(cs.Where(c => c.t == 1).Select(c => c.x).OrderBy(x => -x).Take(n));
		var q2 = new Queue<int>(cs.Where(c => c.t == 2).Select(c => c.x).OrderBy(x => -x).Take(n));
		var c1 = cs.Where(c => c.t == 1).Select(c => c.x).OrderBy(x => -x).Take(n).ToArray();
		//var c2 = cs.Where(c => c.t == 2).Select(c => c.x).OrderBy(x => -x).Take(n).ToArray();

		// どの商品に定額クーポンを使うか
		var p_c1 = new int[n];

		void Push(int pi, int x)
		{
			if (pi + 1 < n && p_c1[pi] > 0)
				Push(pi + 1, p_c1[pi]);
			p_c1[pi] = x;
		}

		// 低いほうから埋める
		for (int ci = c1.Length - 1, pi = n - 1; ci >= 0; ci--)
		{
			while (pi > 0 && c1[ci] > ps[pi])
				pi--;
			Push(pi, c1[ci]);
			if (pi > 0) pi--;
		}

		var r = 0;
		for (int i = 0; i < n; i++)
		{
			var p = ps[i];
			if (p_c1[i] > 0)
			{
				if (q2.Any())
				{
					var t1 = Math.Max(0, p - p_c1[i]);
					var t2 = p - p / 100 * q2.Peek();
					if (t1 < t2)
					{
						r += t1;
					}
					else
					{
						q2.Dequeue();
						r += t2;
						if (i + 1 < n) Push(i + 1, p_c1[i]);
					}
				}
				else
					r += Math.Max(0, p - p_c1[i]);
			}
			else
			{
				if (q2.Any())
					r += p - p / 100 * q2.Dequeue();
				else
					r += p;
			}
		}

		return r;
	}
}
0