cpp
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10;
int n,k,m,t[N],l[N],r[N];
vector<int> g[N];
priority_queue<int,vector<int>,greater<int>> q;
signed main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%d%d",&l[i],&r[i]),t[i]=r[i];
}
sort(t+1,t+n+1);//按右端点排序
for(int i=1;i<=n;i++){
int x=lower_bound(t+1,t+n+1,r[i])-t;//找到第一个大于等于r[i]的下标
g[x].push_back(l[i]); //>=r[i]包含的左端点
}
ll ans=0;t[n+1]=m+1;
for(int i=1;i<=n;i++){
for(int x:g[i])q.push(x);//q相当于小根堆,左端点单调不降
while(q.size()>k)q.pop();
//q.top()左边区间的贡献
//t[i]~t[i+1]区间的贡献,不包括t[i+1]点
if(q.size()==k)ans+=1ll*(t[i+1]-t[i])*(q.top());
}
printf("%lld\n",ans);
}