QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768428#9528. New Energy Vehicle401rk8#WA 0ms9160kbC++171.8kb2024-11-21 10:25:552024-11-21 10:25:57

Judging History

This is the latest submission verdict.

  • [2024-11-21 10:25:57]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 9160kb
  • [2024-11-21 10:25:55]
  • Submitted

answer

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,x,n) memset(a,x,sizeof(*a)*((n)+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }

const int N = 1e5+5;
LL n,m,a[N],p[N],t[N],b[N];
vector<LL> nxt[N];


void MAIN() {
	cin>>n>>m; For(i,1,n) cin>>a[i]; For(i,1,m) cin>>p[i]>>t[i];
	p[++m] = 1e18; For(i,1,n) nxt[i].pb(1e18);
	rFor(i,m,1) nxt[t[i]].pb(p[i]);
	auto cmp=[](int x,int y)
		{ return nxt[x].back()!=nxt[y].back() ? nxt[x].back()<nxt[y].back() : x<y; };
	set<int,decltype(cmp)> s(cmp);
	For(i,1,n) b[i] = a[i], s.emplace(i);
	int u = 0;
	For(i,1,m) {
		for(;;) {
			if( s.empty() ) { cout<<u<<'\n'; return; }
			int j = *s.begin(); s.erase(s.begin());
			int x = min(b[j], p[i]-u);
			u += x, b[j] -= x;
			if( b[j] ) { s.emplace(j); break; }
		}
		s.erase(t[i]), b[t[i]] = a[t[i]], nxt[t[i]].pop_back(), s.emplace(t[i]);
	}
} signed main() {
#ifdef FS
	freopen("in","r",stdin); freopen("out","w",stdout);
#endif
	ios::sync_with_stdio(0);cin.tie(0);
	int lft=read(); while( lft-- ) {
		MAIN();
		For(i,1,n) nxt[i].clear();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

6
11
4
11
999999999
1000000000

result:

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