結果

問題 No.914 Omiyage
ユーザー soto800soto800
提出日時 2019-10-25 21:56:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 3,609 ms
コンパイル使用メモリ 145,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 03:07:01
合計ジャッジ時間 2,098 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){
 
	lli n,m,k;
	cin>>n>>m>>k;

	lli data[12][12];

	REP(i,0,n)REP(j,0,m)cin>>data[i][j];

	/*もっとも小さい10個を選んでいく*/

	vector<lli> index(n);
	REP(i,0,n)index[i]=1;

	lli sum = 0;
	REP(i,0,n)sum+=data[i][0];

	if(sum>k){
		cout<<-1<<endl;
		return 0;
	}
	lli ans = k-sum;

	/*ここから細かく見ていくために,一番増える幅が小さいものを選んでいく*/
	while(1){
		bool breakF = true;

		lli diff=INF;
		lli diffIndex=-1;
		REP(i,0,n){
			if(index[i]>=m)continue;
			if(diff>data[i][index[i]]-data[i][index[i]-1]){
				diff = data[i][index[i]]-data[i][index[i]-1];
				diffIndex=i;
				breakF = false;
			}
		}
		if(breakF)break;

		sum += diff;
		if(k-sum<0)break;
		ans = min(ans,k-sum);
		index[diffIndex]++;
	}
	cout<<ans<<endl;

	return 0;
}
0