#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <utility>
#include <set>
#include <unordered_map>
#include <cmath>
#include <string.h>
#include <cctype>
#include <string>
using namespace std;
using ll = long long;
int main(){
ll n, m;
cin >> n >> m;
ll rs, wk;
ll a;
vector<ll> rates;
vector<ll> weights;
vector<ll> occupied;
unordered_map<ll,ll> spacemem;
for(int i=0; i<n; i++){
occupied.push_back(0);
}
ll totalsum=0;
ll counter=0;
bool occupation=false;
for(int i=0; i<n; i++){
cin >> rs;
rates.push_back(rs);
}
for(int i=0; i<m; i++){
cin >> wk;
weights.push_back(wk);
}
for(int i=0; i<m*2; i++){
cin >> a;
occupation = false;
counter = 0;
if(a>0){
while(occupation==false){
if(occupied[counter]==0){
occupation = true;
occupied[counter]=1;
spacemem[a-1]=counter;
}
else{
counter++;
}
}
totalsum += rates[counter]*weights[a-1];
}
else{
occupied[spacemem[abs(a)-1]]=0;
}
}
cout << totalsum;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
20 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |