QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682557#9528. New Energy VehicleAkoasm_XWA 0ms11816kbC++201.6kb2024-10-27 16:01:112024-10-27 16:01:11

Judging History

This is the latest submission verdict.

  • [2024-10-27 16:01:11]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 11816kb
  • [2024-10-27 16:01:11]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define int long long
typedef long long LL;

inline int read(){
	int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; } 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; } 
    return x * f ;
}

const int maxn = 2e5+20;
int n,m,res;
int x[maxn],t[maxn];
int f[maxn],g[maxn],nxt[maxn],p[maxn];

void solve(){
	n = read();m = read();res = 0;
	for(int i=1;i<=n;i++) res += (f[i] = g[i] = read());
	for(int i=1;i<=m;i++){
        x[i] = read();
        t[i] = read();
    }
	for(int i=1;i<=n;i++){
        x[i+m] = 1e18;
        t[i+m] = i;
	}
	m += n;
	// priority_queue<Node> q;
    priority_queue<int> q;
    for(int i=1;i<=m;i++) q.push(-i);
	for(int i=1;i<=n;i++) p[i] = 0;
	for(int i=m;i>=1;i--){
		// if(p[A[i].t]) nxt[i] = p[A[i].t];
		// else nxt[i] = 0;
        nxt[i] = p[t[i]];
        p[t[i]] = i;
		// p[A[i].t] = i;
	}
	for(int i=1;i<=m;i++){
		if(x[i-1] + res < x[i]){
			printf("%lld\n",res + x[i-1]);
			return ;
		}
		else{
			while(q.size() && -q.top() < i) q.pop();
			int d = x[i] - x[i-1];
            res -= d;
			while(d && q.size()){
				int v = t[-q.top()];
				int tmp = min(d,g[v]);
				g[v] -= tmp;
				d -= tmp;
				if(!g[v]) q.pop();
			}
			if(!g[t[i]] && nxt[i]){
				q.push(nxt[i]);
			}
			res += f[t[i]] - g[t[i]];
			g[t[i]] = f[t[i]];
		}
	}
}

signed main(){
	// freopen("1.txt","r",stdin);
	int T = 1;
	T = read();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 11816kb

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
11
4
11
999999999
2000000000

result:

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