QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141284 | #6532. Trading | cy1999 | WA | 1ms | 3468kb | C++20 | 834b | 2023-08-17 10:15:17 | 2023-08-17 10:15:20 |
Judging History
answer
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=5e5+10;
int t,n,m,ans;
struct node{
int a,b;
}s[N];
bool cmp(node a,node b){
if(a.b>a.a&&b.b>b.a)
return a.b-a.a>b.b-b.a;
if(a.b>a.a&&b.b<=b.a)
return 1;
if(a.b<=a.a&&b.b>b.a)
return 0;
return a.a>b.a;
}
signed main(){
cin>>t;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i].a>>s[i].b;
}
sort(s+1,s+1+n,cmp);
int mid=1;
while(s[mid].b>s[mid].a)mid++;
mid--;
int tmp=m-mid*2-(n-mid);
mid-=max(0ll,0-tmp);
ans=0;
if(mid==n-1){
if(s[n].a+s[n-1].a>s[n].b+s[n-1].b)
mid--;
}
for(int i=1;i<=mid;i++)
ans+=s[i].b;
for(int i=mid+1;i<=n;i++)
if(n>mid+1)
ans+=s[i].a;
else
ans+=s[i].b;
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3468kb
input:
2 4 10 2 30 7 20 4 50 1 2 1 100 1 1000
output:
102 1052
result:
wrong answer 1st numbers differ - expected: '100', found: '102'