#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 j=0;j<k;j++){
for(int i=0;i<n;i++){
if(A[i]<=T[j])
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++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
5 ms |
584 KB |
Output is correct |
4 |
Correct |
4 ms |
588 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
660 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
5 ms |
584 KB |
Output is correct |
4 |
Correct |
4 ms |
588 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
660 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
580 KB |
Output is correct |
14 |
Correct |
304 ms |
3660 KB |
Output is correct |
15 |
Correct |
1176 ms |
6952 KB |
Output is correct |
16 |
Correct |
2617 ms |
10256 KB |
Output is correct |
17 |
Execution timed out |
3069 ms |
13680 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
456 KB |
Output is correct |
3 |
Correct |
5 ms |
584 KB |
Output is correct |
4 |
Correct |
4 ms |
588 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
660 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
580 KB |
Output is correct |
14 |
Correct |
304 ms |
3660 KB |
Output is correct |
15 |
Correct |
1176 ms |
6952 KB |
Output is correct |
16 |
Correct |
2617 ms |
10256 KB |
Output is correct |
17 |
Execution timed out |
3069 ms |
13680 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |