QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657778 | #7622. Yet Another Coffee | wdbl857 | RE | 0ms | 0kb | C++20 | 1.7kb | 2024-10-19 15:26:03 | 2024-10-19 15:26:04 |
answer
#include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define lowbit(x) x & (-x)
typedef pair<int, int> pii;
#define LF(x) fixed << setprecision(x)
#define Yshanqian ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 1e6 + 10, M = 1010, inf = 0x3f3f3f3f, mod = 1e9 + 7, P = 13331;
int n, m;
int a[N], day[N];
void solve()
{
int s1 = 0, s2 = 0;
cin >> n >> m;
vector<int> ans(n + 1, 0);
for (int i = 1; i <= n; i++)
day[i] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i], s1 += a[i];
for (int i = 1; i <= m; i++)
{
int r, w;
cin >> r >> w;
day[r] += w;
s2 += w;
}
multiset<int> st;
for (int i = 2; i <= n; i++)
st.insert(-a[i]);
st.insert(-a[1] + day[1]);
int nowmn = 1, nowval = -a[1] + day[1];
ans[n] = s1 - s2;
for (int i = n - 1; i >= 1; i--)
{
auto it = st.begin();
ans[i] = ans[i + 1] + *it;
if (*it == nowval)
{
st.erase(st.find(*it));
nowmn++;
st.erase(st.find(-a[nowmn]));
st.insert(day[nowmn] - a[nowmn]);
nowval = day[nowmn] - a[nowmn];
}
else
st.erase(st.find(*it));
}
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
cout << endl;
}
signed main()
{
Yshanqian;
int T;
T = 1;
cin >> T;
for (int cases = 1; cases <= T; ++cases)
{
// cout<<"Case #"<<cases<<": ";
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 10 14 17 37 59 65 53 73 68 177 160 111 10 177 5 193 2 30 3 63 2 339 3 263 5 178 2 190 9 23 10 328 10 200 9 8 3 391 6 230 12 9 152 306 86 88 324 59 18 14 42 260 304 55 3 50 2 170 1 252 7 811 1 713 7 215 10 201 4 926 8 319 19 20 182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...