QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198368 | #6517. Computational Geometry | Linx | RE | 0ms | 0kb | C++23 | 745b | 2023-10-03 13:24:48 | 2023-10-03 13:24:49 |
answer
#include<bits/stdc++.h>
#define int ll
#define ll long long
#define ld long double
#define pii pair<int,int>
using namespace std;
int a[1000005],b[1000005],c[1000005];
void solve(){
int n,m;
scanf("%d%d",&n,&m);
ll ans=0;
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
c[i]=b[i]-a[i];
ans+=a[i];
}
sort(c+1,c+n+1);
for(int i=n;i>2;i--){
if(c[i]>0&&m>=n+n-i+1){
ans+=c[i];
}
}
if(m>=n*2-1){
ll cnt=0;
for(int i=1;i<=n;i++){
cnt+=b[i];
}
ans=max(ans,cnt);
}
printf("%lld\n",ans);
}
signed main(){
int t=1;
scanf("%d",&t);
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 4 1 0 2 0 1 1 0 0 6 10 4 9 7 5 7 4 5 6 4 9 3