結果
| 問題 | No.1251 絶対に間違ってはいけない最小化問題 | 
| コンテスト | |
| ユーザー |  どらら | 
| 提出日時 | 2020-10-09 21:42:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 155 ms / 2,000 ms | 
| コード長 | 1,056 bytes | 
| コンパイル時間 | 1,582 ms | 
| コンパイル使用メモリ | 176,492 KB | 
| 実行使用メモリ | 10,756 KB | 
| 最終ジャッジ日時 | 2024-07-20 10:09:39 | 
| 合計ジャッジ時間 | 14,425 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 42 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
int main(){
  int N;
  cin >> N;
  vector<ll> A, B;
  rep(i,N){
    ll a;
    cin >> a;
    A.push_back(a);
  }
  rep(i,N){
    ll b;
    cin >> b;
    B.push_back(b);
  }
  vector<pair<ll,ll>> v;
  rep(i,N){
    v.emplace_back(A[i],B[i]);
  }
  sort(ALLOF(v));
  int lhs = 0, rhs = N-1;
  while(lhs != rhs){
    if(v[lhs].second < v[rhs].second){
      v[rhs].second -= v[lhs].second;
      v[lhs].second -= v[lhs].second;
    }else{
      v[lhs].second -= v[rhs].second;
      v[rhs].second -= v[rhs].second;
    }
    if(v[lhs].second == 0) lhs++;
    if(lhs == rhs) break;
    if(v[rhs].second == 0) rhs--;
  }
  ll x = v[lhs].first;
  ll y = 0;
  rep(i,N){
    y += B[i] * abs(x - A[i]);
  }
  
  cout << x << " " << y << endl;
  
  return 0;
}
            
            
            
        