#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 200010
int N, K, a[MAXN], b[MAXN], t[MAXN];
int seg[4*MAXN];
void update(int node, int l, int r, int idx, int val) {
if(l == r) {
seg[node] = val;
return;
}
if(idx <= mid) update(2*node, l, mid, idx, val);
else update(2*node+1, mid+1, r, idx, val);
seg[node] = max(seg[2*node], seg[2*node+1]);
}
int query(int node, int l, int r, int L, int R) {
if(r < l || R < L || r < L || R < l) return 0;
if(L <= l && r <= R) {
return seg[node];
}
int rez = 0;
if(L <= mid) rez = max(rez, query(2*node, l, mid, L, R));
if(R > mid) rez = max(rez, query(2*node+1, mid+1, r, L, R));
return rez;
}
vector<pii> T;
int bsL(int key) {
int l = 1, r = K, rez = K+1;
while(l <= r) {
if(T[mid].fi >= key) rez = mid, r = mid-1;
else l = mid+1;
}
return rez;
}
int bsR(int key) {
int l = 1, r = K, rez = 0;
while(l <= r) {
if(T[mid].fi <= key) rez = mid, l = mid+1;
else r = mid-1;
}
return rez;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
cin >> N >> K;
for(int i = 1; i <= N; i++) cin >> a[i] >> b[i];
for(int i = 1; i <= K; i++) cin >> t[i];
T.pb({-INF, -INF});
for(int i = 1; i <= K; i++) T.pb({t[i], i});
sort(all(T));
for(int i = 1; i <= K; i++) {
update(1, 1, K, i, T[i].se);
}
lld rez = 0;
for(int i = 1; i <= N; i++) {
int L = bsL(min(a[i], b[i])), R = bsR(max(a[i], b[i])-1);
int sred = query(1, 1, K, L, R);
int vece = query(1, 1, K, L, K);
if(vece == 0) rez += a[i];
else if(sred == vece) rez += max(a[i], b[i]);
else rez += min(a[i], b[i]);
//PRINT(L); PRINT(R);
//PRINT(sred); PRINT(vece);
//PRINT(rez);
}
cout << rez;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |