結果
問題 | No.2852 Yakitori Optimization Problem |
ユーザー |
![]() |
提出日時 | 2024-08-29 13:48:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 906 bytes |
コンパイル時間 | 495 ms |
コンパイル使用メモリ | 45,184 KB |
最終ジャッジ日時 | 2025-02-24 02:41:46 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d%d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | for (int i = 0; i < n; i++) scanf("%d", bs + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | for (int i = 0; i < n; i++) scanf("%d", cs + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2852.cc: No.2852 Yakitori Optimization Problem - yukicoder*/#include<cstdio>#include<algorithm>#include<utility>using namespace std;/* constant */const int MAX_N = 200000;/* typedef */using ll = long long;using pii = pair<int,int>;/* global variables */int as[MAX_N], bs[MAX_N], cs[MAX_N];pii ps[MAX_N];/* subroutines *//* main */int main() {int n, k;scanf("%d%d", &n, &k);for (int i = 0; i < n; i++) scanf("%d", as + i);for (int i = 0; i < n; i++) scanf("%d", bs + i);for (int i = 0; i < n; i++) scanf("%d", cs + i);for (int i = 0; i < n; i++) ps[i] = {cs[i] - bs[i], i};sort(ps, ps + n);ll sum = 0;for (int i = 0; i < k; i++) {int j = ps[i].second;sum += as[j] + bs[j];}for (int i = k; i < n; i++) {int j = ps[i].second;sum += as[j] + cs[j];}printf("%lld\n", sum);return 0;}