結果
| 問題 | No.3761 Moonlit Battle |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2026-10-09 23:31:36 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,280 bytes |
| 記録 | |
| コンパイル時間 | 1,060 ms |
| コンパイル使用メモリ | 186,720 KB |
| 実行使用メモリ | 31,988 KB |
| 最終ジャッジ日時 | 2026-10-09 23:31:48 |
| 合計ジャッジ時間 | 6,779 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 WA * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main()
{
int n, d;
cin >> n >> d;
vector<pair<int, long long>> ba;
{
map<int, long long> ab;
ab[0] = d + 1;
for (int i = 0; i < n; ++i)
{
int a, b;
cin >> a >> b;
ab[b] += a;
}
for (auto [b, a] : ab) ba.push_back({b, a});
reverse(ba.begin(), ba.end());
}
long long sum = 0;
n = ba.size();
int id = n;
for (int i = 0; i < n; ++i)
{
sum += ba[i].second;
if (sum >= d)
{
id = i;
break;
}
}
long long ans = 0;
map<int, long long> mp;
int tob = ba[id].first;
for (int i = 0; i < id; ++i)
{
auto [b, a] = ba[i];
long long c = (b - tob) / d;
ans += c * ba[i].second;
ba[i].first -= c * d;
}
for (int i = 0; i < n; ++i)
{
auto [b, a] = ba[i];
mp[b] += a;
}
long long now = ans;
ans = ans + mp.rbegin()->first;
int cnt = 0;
while (mp.rbegin()->first > 0)
{
auto itr = mp.end();
--itr;
int b = itr->first;
int a = itr->second;
mp.erase(mp.find(b));
b -= d;
mp[b] += a;
now += a;
ans = min(ans, now + mp.rbegin()->first);
++cnt;
if (cnt >= 2 * n) break;
}
cout << ans << endl;
}
テナガザル