結果
| 問題 | No.1251 絶対に間違ってはいけない最小化問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-10 17:29:20 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 778 bytes |
| 記録 | |
| コンパイル時間 | 586 ms |
| コンパイル使用メモリ | 93,040 KB |
| 実行使用メモリ | 127,588 KB |
| 最終ジャッジ日時 | 2026-04-03 01:13:50 |
| 合計ジャッジ時間 | 7,910 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:31:30: warning: 'piv' may be used uninitialized [-Wmaybe-uninitialized]
31 | ans += (ll)b[i] * abs(piv-a[i]);
| ~~~^~~~~~~~~~
main.cpp:21:17: note: 'piv' was declared here
21 | ll acc = 0, piv;
| ^~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n], b[n];
ll sum = 0;
vector<pii> vp;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i], sum += b[i], vp.push_back({a[i], b[i]});
sort(vp.begin(), vp.end());
ll acc = 0, piv;
for(int i = 0; i < n; i++){
acc += vp[i].second;
if(acc >= (sum+1)/2){
piv = vp[i].first;
break;
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
ans += (ll)b[i] * abs(piv-a[i]);
}
cout << piv << " " << ans << endl;
return 0;
}