QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692370#9528. New Energy VehiclerefWA 18ms8332kbC++201.8kb2024-10-31 14:24:082024-10-31 14:24:09

Judging History

This is the latest submission verdict.

  • [2024-10-31 14:24:09]
  • Judged
  • Verdict: WA
  • Time: 18ms
  • Memory: 8332kb
  • [2024-10-31 14:24:08]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
typedef pair<int,int> PII;
const int N=1e5+10;
const int inf=1e18;
int a[N];
int b[N];
PII xt[N];
int n,m;
int st[N];
void solve()
{
    int ans=0;
    int res=0;
    cin>>n>>m;
    stack<int>q;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        st[i]=0;
        res+=a[i];
        q.push(i);
        b[i]=a[i];
    }
    xt[0].first=0;
    for(int i=1;i<=m;i++)
    {
        cin>>xt[i].first>>xt[i].second;
        st[xt[i].second]=1;
    }
    sort(xt+1,xt+1+m);
    for(int i=m;i>=1;i--)
    {
        q.push(xt[m].second);
    }
    for(int i=1;i<=m;i++)
    {
        int u=xt[i].first;
        int v=xt[i].second;
        if(a[v]>=u-ans)
        {
            ans=u;
        }
        else
        {
            res=0;
            while(!q.empty())
            {
                int sb=q.top();
                q.pop();
                if(a[sb]!=0)
                {
                    res+=a[sb];
                    a[sb]=0;
                }
                if(res>=u-ans)
                {
                    a[sb]=res-(u-ans);
                    a[v]=b[v];
                    q.push(a[sb]);
                    q.push(b[v]);
                    ans=u;
                    res=0;
                    break;
                }
            }
            ans+=res;
            if(q.empty())
            {
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans+=a[i];
    }
    cout<<ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int t;
	while(cin>>t)
	{
        while(t--)
        {   
            solve();
        }
    }
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 5624kb

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:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 18ms
memory: 8332kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1301430
1556387
773402
1508121
1130008
1549533
636680
1527997
660341
627885

result:

wrong answer 1st lines differ - expected: '1543020', found: '1301430'