#include <iostream>
using namespace std;
typedef pair < int, int > PII;
const int NMAX = 2e5 + 5, KMAX = 2e5 + 5;
int N, K;
PII A[NMAX];
int T[KMAX];
static inline void Read ()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
for(int i = 1; i <= N; ++i)
cin >> A[i].first >> A[i].second;
for(int i = 1; i <= K; ++i)
cin >> T[i];
return;
}
static inline void Solve ()
{
long long ans = 0;
for(int i = 1; i <= N; ++i)
{
int Last_Index = 0;
int Min = min(A[i].first, A[i].second);
int Max = max(A[i].first, A[i].second);
for(int j = K; j >= 1 && !Last_Index; --j)
if(T[j] >= Min && T[j] < Max)
Last_Index = j;
if(Last_Index && A[i].first < A[i].second)
swap(A[i].first, A[i].second);
for(int j = Last_Index + 1; j <= K; ++j)
if(T[j] >= Max)
swap(A[i].first, A[i].second);
ans += 1LL * A[i].first;
}
cout << ans << '\n';
return;
}
int main()
{
Read();
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
11 ms |
512 KB |
Output is correct |
15 |
Correct |
17 ms |
640 KB |
Output is correct |
16 |
Correct |
21 ms |
640 KB |
Output is correct |
17 |
Correct |
26 ms |
744 KB |
Output is correct |
18 |
Correct |
26 ms |
896 KB |
Output is correct |
19 |
Correct |
24 ms |
896 KB |
Output is correct |
20 |
Correct |
46 ms |
768 KB |
Output is correct |
21 |
Correct |
22 ms |
896 KB |
Output is correct |
22 |
Correct |
19 ms |
768 KB |
Output is correct |
23 |
Correct |
19 ms |
768 KB |
Output is correct |
24 |
Correct |
22 ms |
768 KB |
Output is correct |
25 |
Correct |
18 ms |
768 KB |
Output is correct |
26 |
Execution timed out |
3076 ms |
768 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
11 ms |
512 KB |
Output is correct |
15 |
Correct |
17 ms |
640 KB |
Output is correct |
16 |
Correct |
21 ms |
640 KB |
Output is correct |
17 |
Correct |
26 ms |
744 KB |
Output is correct |
18 |
Correct |
26 ms |
896 KB |
Output is correct |
19 |
Correct |
24 ms |
896 KB |
Output is correct |
20 |
Correct |
46 ms |
768 KB |
Output is correct |
21 |
Correct |
22 ms |
896 KB |
Output is correct |
22 |
Correct |
19 ms |
768 KB |
Output is correct |
23 |
Correct |
19 ms |
768 KB |
Output is correct |
24 |
Correct |
22 ms |
768 KB |
Output is correct |
25 |
Correct |
18 ms |
768 KB |
Output is correct |
26 |
Execution timed out |
3076 ms |
768 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |