結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 21:45:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 576 bytes |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 199,012 KB |
| 最終ジャッジ日時 | 2025-01-15 04:21:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | int n; scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | rep(i,n) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | rep(i,n) scanf("%lld",&b[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n; scanf("%d",&n);
vector<lint> a(n),b(n);
rep(i,n) scanf("%lld",&a[i]);
rep(i,n) scanf("%lld",&b[i]);
vector<int> p(n);
iota(p.begin(),p.end(),0);
sort(p.begin(),p.end(),[&](int i,int j){
return a[i]<a[j];
});
lint bsum=accumulate(b.begin(),b.end(),0LL);
lint tmp=0;
for(int i:p){
tmp+=b[i];
if(2*tmp>=bsum){
lint ans=0;
rep(j,n) ans+=b[j]*abs(a[j]-a[i]);
printf("%lld %lld\n",a[i],ans);
break;
}
}
return 0;
}