結果

問題 No.914 Omiyage
ユーザー iqueue02iqueue02
提出日時 2019-10-25 22:55:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 861 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 176,560 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 11:14:00
合計ジャッジ時間 2,967 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

vector<vector<int>> a;
int n, m, k;
/* 
int dfs(int i, int now){
  if (now > k) return -1;
  if (i == n) return now;
  int ret = -1;
  for (auto e : a[i]) {
    int t = dfs(i+1,now + e);
    if (t == -1) break;
    ret = max(ret,t);
  }
  return ret;
}
*/
int main(){
  
  cin >> n >> m >> k;
  a.resize(n);

  int value = 0;

  rep(i,n) rep(j,m) {
    int c;
    cin >> c;
    if (j == 0) value += c;
    a[i].push_back(c);
  }
  sort(a.begin(), a.end());
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (value - a[j][i-1] + a[j][i] <= k) value += a[j][i] - a[j][i-1];
    }
  }
  if (value > k) cout << -1 << endl;
  else cout << k - value << endl;
  
  return 0;
}
0