QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720338#9528. New Energy VehicleteaWA 0ms3640kbC++172.9kb2024-11-07 11:58:052024-11-07 11:58:05

Judging History

This is the latest submission verdict.

  • [2024-11-07 11:58:05]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3640kb
  • [2024-11-07 11:58:05]
  • Submitted

answer

// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define pb push_back
#define st first
#define nd second
#define PII pair<ll, ll>
#define D(x, y) cout << x << "=" << y << endl;
#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
// #define int long long
// #define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
const int M = 1e9+7;
inline ll read()
{
    ll x = 0;
    bool f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar())
        if (c == '-')
            f = 0;
    for (; isdigit(c); c = getchar())
        x = (x << 3) + (x << 1) + c - '0';
    return f ? x : 0 - x;
}
inline void out(ll x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        out(x / 10);
    putchar(x % 10 + '0');
}
// __int128 rd()
// {
// 	char arr[30];
// 	__int128 res = 0;
// 	scanf("%s", arr);
// 	for (int i = 1; i <= strlen(arr); i++)
// 	{
// 		res *= 10;
// 		res += arr[i]-'0';
// 	}
// 	return res;
// }
// void pt(__int128 num)
// {
// 	if (num > 9) pt(num / 10);
// 	putchar(num % 10 + '0');
// }

ll n, m;
ll a[N];
vector< PII >v;
void solve()
{
    cin>>n>>m;
    queue<ll>q[n+5];
    rep(i,1,n+1) cin>>a[i];
    rep(i,0,m)
    {
        ll x,y;cin>>x>>y;
        v.pb({x,y});q[y].push(x);
    }
    rep(i,1,n+1) q[i].push(inf);
    sort(v.begin(),v.end());
    priority_queue<PII,vector<PII>,greater<PII> >qr,qr1;
    rep(i,1,n+1)
    {
        qr.push({q[i].front(),i});q[i].pop();
    }
    ll d=0,ans=0;
    rep(i,0,m)
    {
        ll x = v[i].st;
        while(x!=0)
        {//D("x",x);
            if(!qr.empty())
            {
                if(a[qr.top().nd]-d<=x)
                {
                    qr1.push(qr.top());
                    x-=a[qr.top().nd]-d;
                    d=0;qr.pop();
                }
                else 
                {
                    d+=x;
                    break;
                }
            }
            else return cout<<ans+v[i].st-x<<endl,void();
        }//D("d",d);
        if(qr1.empty()) d=0;
        else 
        {
            ll t=qr1.top().nd;
            if(!q[t].empty())
            {
                qr.push({q[t].front(),t});
                q[t].pop();
            }
            qr1.pop();
            ans=v[i].st;
        }
    }
    while(!qr.empty()) 
    {
        ans+=a[qr.top().nd];
        qr.pop();
    }
    cout<<ans-d<<endl;
}
signed main()
{
    IOS
        // freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
        ll T = 1;
    cin >> T;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

8
9
6
6
999999999
1000000000

result:

wrong answer 1st lines differ - expected: '9', found: '8'