結果

問題 No.3527 Minimum Abs Sum
コンテスト
ユーザー Carpenters-Cat
提出日時 2026-05-04 21:37:44
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 841 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,987 ms
コンパイル使用メモリ 279,108 KB
実行使用メモリ 9,696 KB
最終ジャッジ日時 2026-05-04 21:37:59
合計ジャッジ時間 6,001 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
int main () {
	int N;
	cin >> N;
	std::vector<long long> A(N), B(N);
	for (auto& a : A) cin >> a;
	for (auto& b : B) cin >> b;
	for (int i = 0; i < N; i ++) {
		if (A[i] < 0) {
			A[i] *= -1;
			B[i] *= -1;
		}
	}
	{
		vector<long long> C, D;
		for (int i = 0; i < N; i ++) {
			if (A[i]) {
				C.push_back(A[i]);
				D.push_back(B[i]);
			}
		}
		A = C; B = D;
	}
	int M = A.size();
	vector<int> ID(M);
	iota(ID.begin(), ID.end(), 0);
	sort(ID.begin(), ID.end(), [&](int i, int j) {return B[i] * A[j] <= B[j] * A[i];});
	long long D = -accumulate(A.begin(), A.end(), 0ll);
	for (auto& i : ID) {
		D += 2 * A[i];
		if (D >= 0) {
			mint ans = B[i];
			ans /= A[i];
			cout << ans.val() << endl;
			return 0;
		}
	}
}
0