#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int to[2000005],yes[2000005],tp;
pii tran[1000005],pl[2000005];
const int INF=1e9,MAXC=2000001;
bitset<2000005> vis;
int main()
{jizz
int n,m,all,ans=0;
cin >> n >> m,all=2*n+1;
for(int i=0;i<n;++i)
cin >> tran[i].F >> tran[i].S,pl[i<<1]=MP(tran[i].F,i<<1),pl[i<<1|1]=MP(tran[i].S,i<<1|1);
pl[all-1]=MP(MAXC,all-1),to[all-1]=-1,vis[all-1]=1;
sort(pl,pl+all);
for(int i=0;i<n;++i)
{
to[i<<1]=upper_bound(pl,pl+all,MP(tran[i].S,INF))->S;
to[i<<1|1]=upper_bound(pl,pl+all,MP(tran[i].F,INF))->S;
}
for(int i=pl[0].S;!vis[i];i=to[i])
vis[i]=1,++ans;
for(int i=0;i<all;++i)
if(!vis[i])
{
int tmp=0;
for(int j=i;!vis[j];j=to[j])
vis[j]=1,++tmp;
yes[tp++]=tmp;
}
sort(yes,yes+tp);
for(int i=tp-1;i>=0&&m;--i)
--m,ans+=yes[i]+2;
if(m&1)
cout << ans+(m-1)*2+1 << "\n";
else
cout << ans+m*2 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
768 KB |
Output is correct |
3 |
Correct |
20 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
4528 KB |
Output is correct |
2 |
Correct |
255 ms |
10316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
7516 KB |
Output is correct |
2 |
Correct |
386 ms |
15004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
571 ms |
21784 KB |
Output is correct |
2 |
Correct |
750 ms |
26200 KB |
Output is correct |
3 |
Correct |
819 ms |
29560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
28696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
34472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |