QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691368 | #9528. New Energy Vehicle | Willis | RE | 0ms | 0kb | C++20 | 3.1kb | 2024-10-31 11:09:51 | 2024-10-31 11:09:57 |
Judging History
answer
#ifdef local
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#endif
// #pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#ifndef local
#define endl '\n'
#endif
#define pb emplace_back
#define fi first
#define se second
#define rep(i, l, r) for (long long i = l; i <= r; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
const double pi = acos(-1);
typedef __int128_t int128;
const db eps = 1e-9;
std::mt19937_64 rng(time(0));
ll my_random(ll l, ll r)
{
uniform_int_distribution<int> range(l, r);
return range(rng);
}
void __()
{
#ifdef local
system("pause");
#endif
}
ll qp(ll a, ll b, ll mod)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
const int maxn = 1e5 + 10;
int n, m;
ll a[maxn];
ll x[maxn], t[maxn];
ll mx[maxn];
vector<int> vec[maxn];
ll pos[maxn];
int main()
{
IOS;
int _;
cin >> _;
while (_--)
{
cin >> n >> m;
for (int i = 1; i <= n + 5; i++)
vec[i].clear(), pos[i] = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
mx[i] = a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> x[i] >> t[i];
vec[t[i]].pb(i);
}
x[m + 1] = 2e18;
priority_queue<P, vector<P>, greater<P>> q;
for (int i = 1; i <= n; i++)
{
if (vec[i].size() == 0)
q.push(P{m + i, i});
else
q.push(P{vec[i][pos[i]], i});
}
ll ans = 0;
int flg = 1;
while (q.size())
{
P p = q.top();
q.pop();
int pos2 = p.se; // use dianping
ll length = a[pos2];
ll canrun = min(x[flg] - ans, length);
ans += canrun;
a[pos2] -= canrun;
if (ans == x[flg])
{
int chongdian = t[flg];
a[chongdian] = mx[chongdian]; // chongdian
if (a[pos2] != 0 && pos2 != chongdian)
{
if (pos[pos2] == vec[pos2].size()-1)
q.push(P{m + pos2, pos2});
else
q.push(P{vec[pos2][pos[pos2]], pos2});
}
if (pos[chongdian] == vec[chongdian].size() - 1)
q.push(P{m + chongdian, chongdian});
else
pos[chongdian]++, q.push(P{vec[chongdian][pos[chongdian]], chongdian});
flg++;
}
// priority_queue<P, vector<P>, greater<P>> q2 = q;
// //cout << "XX " << ans << endl;
// while (q2.size())
// {
// P p = q2.top();
// q2.pop();
// //cout << p.fi << " " << p.se << " " << a[p.se] << endl;
// }
// //cout << endl;
}
cout << ans << endl;
}
__();
return 0;
}
/*
1
3 5
1 50 500
1 1
45 2
100 2
300 3
500 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1