結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:35:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 875 bytes |
コンパイル時間 | 2,065 ms |
コンパイル使用メモリ | 200,472 KB |
最終ジャッジ日時 | 2025-01-15 05:18:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 1 WA * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(I,A,B) for(int I = int(A); I < int(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);} ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);} int main(){ ll N; cin >> N; vector<pair<ll,ll>> AB(N); FOR(i,0,N) cin >> AB[i].first; FOR(i,0,N) cin >> AB[i].second; sort(AB.begin(), AB.end()); ll f=0,X=AB[0].first; ll add = 0; FOR(i,1,N){ f += AB[i].second * (AB[i].first - X); add += -AB[i].second; } ll ansf = f, ansX = X; add += AB[0].second; FOR(i,1,N){ f += add * (AB[i].first - AB[i-1].first); if(f < ansf) { ansf = f; X = AB[i].first; } add += 2*AB[i].second; } cout << ansX << " " << ansf << endl; }