#include <bits/stdc++.h>
using namespace std;
vector<int64_t> a;
vector<pair<int64_t,int64_t>> b;
///find the largest number less than x
#define INF (1000000001)
int64_t cnp(int64_t l, int64_t r, int64_t x)
{
if(l>r) return -1;
if(l==r)
{
if(a[l]<=x)
{
return l;
}
return -1;
}
int64_t mid = (l+r)/2;
int64_t xx = a[mid];
if(a[mid]<=x)
return max(mid,cnp(mid+1,r,x));
return cnp(l,mid-1,x);
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int64_t n, k;
cin >> n >> k;
b.resize(n);
a.resize(k+2);
a[0] = -1;
a[1] = -1;
for(int64_t i = 0;i<n;i++)
cin >> b[i].first >> b[i].second;
for(int64_t i = 0;i<k;i++)
cin >> a[i+2];
sort(a.begin(),a.end());
k+=4;
a.push_back(INF);
a.push_back(INF);
int64_t sum = 0;
for(int64_t i = 0;i<n;i++)
{
int64_t l = cnp(0,k-1,min(b[i].first,b[i].second));
int64_t r = cnp(0,k-1,max(b[i].first,b[i].second));
int64_t gd1 = r-l+1;
int64_t gd2 = (k-r)%2;
if(gd1==0)
{
sum+=b[i].first;
continue;
}
if(b[i].first>b[i].second)
{
if(gd2==0)
{
sum+=b[i].first;
continue;
}
sum+=b[i].second;
continue;
}
if(gd2==0)
{
sum+=b[i].second;
continue;
}
sum+=b[i].first;
continue;
}
cout << sum;
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'int64_t cnp(int64_t, int64_t, int64_t)':
fortune_telling2.cpp:20:13: warning: unused variable 'xx' [-Wunused-variable]
int64_t xx = a[mid];
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |