Submission #899586

#TimeUsernameProblemLanguageResultExecution timeMemory
899586josanneo22Garage (IOI09_garage)C++17
100 / 100
1 ms604 KiB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

#define L(i,j,k) for(int i=j;i<=k;i++)
#define R(i,j,k) for(int i=j;i>=k;i--)

constexpr int _N = 1E4 + 500;
int N, M, R[_N], W[_N], pos[_N];
queue<int> q;

int main() {
	scanf("%d%d", &N,&M);
	L(i,1,N) scanf("%d", &R[i]);
	L(i,1,M) scanf("%d", &W[i]);
	set<int> S;
	L(i,1,N) S.insert(i);
	int ans=0;
	L(i,1,2*M){
		int x; scanf("%d",&x);
		if(x<0){
			x=abs(x);
			if(q.empty()){
				S.insert(pos[x]);
			}
			else{
				int f=q.front(); q.pop();
				pos[f]=pos[x];
				ans+=W[f]*R[pos[f]];
			}
		}
		else{
			if(S.empty()){
				q.push(x);
			}
			else{
				int where=*S.begin();
				pos[x]=where;
				ans+=W[x]*R[where];
				S.erase(S.begin());
			}
		}
	}
	printf("%d", ans);
}

Compilation message (stderr)

garage.cpp: In function 'int main()':
garage.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d", &N,&M);
      |  ~~~~~^~~~~~~~~~~~~~~
garage.cpp:14:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  L(i,1,N) scanf("%d", &R[i]);
      |           ~~~~~^~~~~~~~~~~~~
garage.cpp:15:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  L(i,1,M) scanf("%d", &W[i]);
      |           ~~~~~^~~~~~~~~~~~~
garage.cpp:20:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   int x; scanf("%d",&x);
      |          ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...