結果
| 問題 | No.3527 Minimum Abs Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-04 22:34:30 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,309 bytes |
| 記録 | |
| コンパイル時間 | 2,059 ms |
| コンパイル使用メモリ | 345,464 KB |
| 実行使用メモリ | 11,988 KB |
| 最終ジャッジ日時 | 2026-05-04 22:34:36 |
| 合計ジャッジ時間 | 5,065 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
int power(int a, int b){
int res = 1;
while(b){
if(b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int inv(int a){
return power(a, MOD - 2);
}
signed main() {
int n;
cin >> n;
vector<int> a;
vector<int> b;
for(int i = 0; i < n; i++){
int m;
cin >> m;
a.push_back(m);
}
for(int i = 0; i < n; i++){
int m;
cin >> m;
b.push_back(m);
}
vector<pair<int,int>> c;
for(int i = 0; i < n; i++){
if(a[i] != 0){
c.push_back({b[i], a[i]});
}
}
sort(c.begin(), c.end(), [](pair<int,int> x, pair<int,int> y){
return x.first * y.second < y.first * x.second;
});
int total = 0;
for(auto &x : c){
total += abs(x.second);
}
int cur = 0;
int p = 0, q = 1;
for(auto &x : c){
cur += abs(x.second);
if(cur * 2 >= total){
p = x.first;
q = x.second;
break;
}
}
if(q < 0){
p = -p;
q = -q;
}
p = (p % MOD + MOD) % MOD;
q = (q % MOD + MOD) % MOD;
int ans = p * inv(q) % MOD;
cout << ans;
}