QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244491 | #4488. Buy Figurines | ucup-team203# | AC ✓ | 1767ms | 56608kb | C++20 | 1.7kb | 2023-11-09 10:07:24 | 2023-11-09 10:07:25 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
const int N = 2e5 + 5;
// const int B = 400;
// const int M = 4e6 + 5;
// const int base = 15171;
// const int mod = 998244353;
// const i64 mod = (i64)1e18 + 7;
// const double pi = acos(-1);
int n, m, num[N];
i64 lst[N];
array<int, 2> a[N];
struct node
{
int id;
bool operator<(const node &tmp) const
{
if (num[id] == num[tmp.id])
return id < tmp.id;
return num[id] < num[tmp.id];
}
};
void solve()
{
cin >> n >> m;
set<i64> times;
map<i64, vector<int>> del;
for (int i = 1; i <= n; i++)
cin >> a[i][0] >> a[i][1], times.insert(a[i][0]);
sort(a + 1, a + n + 1);
set<node> st;
for (int i = 1; i <= m; i++)
st.insert({i});
int p = 1;
for (auto &t : times)
{
while (p <= n && a[p][0] == t)
{
auto [id] = *st.begin();
st.erase({id});
i64 cur = max((i64)a[p][0], lst[id]) + a[p][1];
times.insert(cur);
del[cur].push_back(id);
num[id]++;
lst[id] = cur;
p++;
st.insert({id});
}
if (del.count(t))
{
for (int i : del[t])
{
st.erase({i});
num[i]--;
st.insert({i});
}
}
}
cout << *max_element(lst + 1, lst + m + 1) << '\n';
for (int i = 1; i <= m; i++)
lst[i] = 0;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
// cout << fixed << setprecision(10);
while (t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1767ms
memory: 56608kb
input:
8 5 3 2 4 1 3 5 1 3 4 4 2 200000 200000 26113860 1563 45251761 2156 63941612 4551 16962783 4576 18965664 5853 4091010 2401 10238760 7732 19457520 7279 7641592 4270 24241152 7862 51178555 8548 31253040 7967 2966632 5745 59550817 1824 4312590 7419 81579464 2401 20977992 8997 28997820 6485 3132935 9527...
output:
7 99184946 99609939 27024359944 26923428235 4992516018218 93791976 117811694
result:
ok 8 lines