結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
|
提出日時 | 2020-10-10 17:29:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 778 bytes |
コンパイル時間 | 762 ms |
コンパイル使用メモリ | 77,808 KB |
実行使用メモリ | 6,772 KB |
最終ジャッジ日時 | 2024-07-20 16:04:57 |
合計ジャッジ時間 | 12,804 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:33:13: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'piv' may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': 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; }