結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
ysystem7
|
| 提出日時 | 2020-10-09 21:53:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,814 bytes |
| コンパイル時間 | 2,612 ms |
| コンパイル使用メモリ | 227,040 KB |
| 最終ジャッジ日時 | 2025-01-15 04:31:36 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:22: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
67 | ans+=b[i]*abs(a[i]-x);
| ~~~^~~~~~~~
main.cpp:47:8: note: ‘x’ was declared here
47 | ll x;
| ^
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}
const ll INF=1e18;
const int mx=200005;
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ll n;
cin>>n;
V<ll> a(n),b(n);
//V<ll> cnt1(1000001,0);
map<ll,ll> mp;
rep(i,n){
cin>>a[i];
mp[a[i]]++;
}
rep(i,n) cin>>b[i];
V<P> p(n);
ll x;
ll sum=0;
for(auto tmp:mp){
p.emplace_back(tmp.ft,tmp.sc);
/*sum+=tmp.sc;
if(sum>=(n+1)/2){
x=tmp.ft;
break;
}*/
}
sort(all(p));
rep(i,(int)p.size()){
sum+=p[i].sc;
if(sum>=(n+1)/2){
x=p[i].ft;
break;
}
}
ll ans=0;
rep(i,n){
ans+=b[i]*abs(a[i]-x);
}
cout<<x<<' '<<ans<<endl;
}
ysystem7