QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685216#9528. New Energy Vehiclety09WA 0ms3600kbC++201.1kb2024-10-28 18:19:482024-10-28 18:19:50

Judging History

This is the latest submission verdict.

  • [2024-10-28 18:19:50]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3600kb
  • [2024-10-28 18:19:48]
  • Submitted

answer

// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr)
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define T() int ____t;cin>>____t;while(____t--)
using namespace std;
constexpr int N=2e6+10,mod=1e9+7;

#define int ll

void solve(){
	int n,m;
	cin>>n>>m;
	vector<int>a(n+1),b(n+1);
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
		sum+=a[i];
	}
	vector<int>t(m+1),x(m+1);
	for(int i=1;i<=m;i++){
		cin>>x[i]>>t[i];
	}
	int cha=0;
	for(int i=1;i<=m;i++){
		if(sum>=x[i]-x[i-1]){
			sum-=(x[i]-x[i-1]);
		}
		else{
			cout<<x[i-1]+sum<<endl;
			return;
		}
		
		if(a[t[i]]-(x[i]-x[i-1])>=0){
			sum+=(x[i]-x[i-1])+min(a[t[i]]-(x[i]-x[i-1]),cha);
			if(cha<=a[t[i]]-(x[i]-x[i-1])){
				cha=0;
			}
			else{
				cha-=( a[t[i]]-(x[i]-x[i-1]) );
			}
		}
		if(a[t[i]]-(x[i]-x[i-1])<0){
			sum+=a[t[i]];
			cha+=abs(a[t[i]]-(x[i]-x[i-1]));
		}
	}
	cout<<x[m]+sum<<endl;
	return;
}
signed main()
{
	ios;
	T()
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

10
11
4
11
999999999
2000000000

result:

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