#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int n, k;
vector<int>A, B, T;
map<int, int>mp, inv;
void pre(){
A.clear(), B.clear(), T.clear(), mp.clear(), inv.clear();
A.resize(n), B.resize(n), T.resize(k);
}
void comp(){
vector<int>S=T;
for(int i=0;i<n;i++){
S.push_back(A[i]);
S.push_back(B[i]);
}
sort(all(S));
int cnt=1;
for(int i=0;i<S.size();i++){
if(!i || S[i]!=S[i-1]){
mp[S[i]]=cnt, inv[cnt]=S[i], cnt++;
}
}
for(int i=0;i<n;i++){
A[i]=mp[A[i]], B[i]=mp[B[i]];
}
for(int j=0;j<k;j++){
T[j]=mp[T[j]];
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k;
pre();
for(int i=0;i<n;i++){
cin>>A[i]>>B[i];
}
for(int j=0;j<k;j++){
cin>>T[j];
}
comp();
for(int i=0;i<n;i++){
vector<int>T2;
int cnt=0;
int mn=min(A[i], B[i]), mx=max(A[i], B[i]);
for(int j=0;j<k;j++){
if(T[j]>=mx)
cnt++;
else if(T[j]>=mn)
T2.push_back(1);
if(j==k-1 || (T[j+1]>=mn && T[j+1]<mx)){
if(cnt&1)
T2.push_back(2);
cnt=0;
}
}
for(int j=0;j<T2.size();j++){
if(A[i]==mn)
swap(A[i], B[i]);
else if(T2[j]==2)
swap(A[i], B[i]);
}
}
ll ans=0;
for(int i=0;i<n;i++){
ans+=inv[A[i]];
}
cout<<ans;
}
Compilation message
fortune_telling2.cpp: In function 'void comp()':
fortune_telling2.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<S.size();i++){
| ~^~~~~~~~~
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j=0;j<T2.size();j++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
596 KB |
Output is correct |
4 |
Correct |
9 ms |
664 KB |
Output is correct |
5 |
Correct |
9 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
660 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
656 KB |
Output is correct |
9 |
Correct |
8 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
596 KB |
Output is correct |
4 |
Correct |
9 ms |
664 KB |
Output is correct |
5 |
Correct |
9 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
660 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
656 KB |
Output is correct |
9 |
Correct |
8 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
746 ms |
3628 KB |
Output is correct |
15 |
Correct |
2861 ms |
6956 KB |
Output is correct |
16 |
Execution timed out |
3055 ms |
10276 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
596 KB |
Output is correct |
4 |
Correct |
9 ms |
664 KB |
Output is correct |
5 |
Correct |
9 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
660 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
656 KB |
Output is correct |
9 |
Correct |
8 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
746 ms |
3628 KB |
Output is correct |
15 |
Correct |
2861 ms |
6956 KB |
Output is correct |
16 |
Execution timed out |
3055 ms |
10276 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |