Submission #29492199
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class F> ll optimize(int low, int high, const F& f) {
while (high - low > 2) {
const int m1 = (low + high) / 2;
const int m2 = m1 + 1;
if (f(m1) < f(m2)) {
low = m1;
} else {
high = m2;
}
}
return f(low + 1);
}
void solve() {
int n, m;
cin >> n >> m;
ll a = 0, b = 0, ans = numeric_limits<ll>::min();
for (int i = 0; i < n; ++i) {
ll x, y;
cin >> x >> y;
const auto f = [&](const int k) {
return a + b * k + x * k * (k + 1) / 2;
};
if (x > 0) {
ans = max(ans, f(1));
ans = max(ans, f(y));
} else {
ans = max(ans, optimize(0, y + 1, f));
}
a = f(y);
b += x * y;
}
cout << ans << '\n';
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Sum Sum Max |
| User | KoD |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 1029 Byte |
| Status | AC |
| Exec Time | 486 ms |
| Memory | 3596 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt |
| All | example_00.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 8 ms | 3528 KiB |
| test_00.txt | AC | 486 ms | 3576 KiB |
| test_01.txt | AC | 96 ms | 3436 KiB |
| test_02.txt | AC | 86 ms | 3596 KiB |
| test_03.txt | AC | 77 ms | 3400 KiB |
| test_04.txt | AC | 75 ms | 3596 KiB |
| test_05.txt | AC | 78 ms | 3524 KiB |
| test_06.txt | AC | 75 ms | 3416 KiB |
| test_07.txt | AC | 85 ms | 3596 KiB |
| test_08.txt | AC | 63 ms | 3528 KiB |
| test_09.txt | AC | 43 ms | 3532 KiB |
| test_10.txt | AC | 178 ms | 3412 KiB |