QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472817 | #6525. New Houses | zzisjtu# | WA | 89ms | 3588kb | C++23 | 1.4kb | 2024-07-11 19:32:34 | 2024-07-11 19:32:34 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
#define LF(x) fixed<<setprecision(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
struct val
{
ll a,b;
bool vis;
};
void solve()
{
int n,m;
cin>>n>>m;
int cnt=0;//更喜欢没有邻居的人数
vector<val>x(n+1);
for(int i=1;i<=n;i++){
cin>>x[i].a>>x[i].b;
if(x[i].b>x[i].a)cnt++;
x[i].vis=false;
}
if(cnt==0){
ll sum=0;
for(int i=1;i<=n;i++){
sum+=x[i].a;
}
cout<<sum<<endl;
return;
}
/*
sort(x.begin()+1,x.end(),[&](val t1,val t2){
return t1.b>t2.b;
});
*/
sort(x.begin()+1,x.end(),[&](val t1,val t2){
return t1.b>t2.b;
});
vector<ll>sum1(n+1),sum2(n+1);
for(int i=1;i<=n;i++){
sum1[i]=sum1[i-1]+x[i].b;
sum2[i]=sum2[i-1]+x[i].a;
}
ll ans=0;
for(int i=0;i<=n;i++){
if((n-i>=2&&i+n<=m)||(n==i&&2*n-1<=m)){
// cout<<i<<endl;
ll res=sum1[i];
res+=sum2[n]-sum2[i];
ans=max(ans,res);
}
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 4 5 1 100 100 1 100 1 100 1 2 2 1 10 1 10 2 3 100 50 1 1000
output:
400 2 1050
result:
ok 3 number(s): "400 2 1050"
Test #2:
score: -100
Wrong Answer
time: 89ms
memory: 3532kb
input:
100000 6 11 191141536 365120521 799679686 648574232 102602909 467685128 405440859 796808887 384858152 191995380 433392826 195648471 5 13 831367906 510447872 795639287 575551283 811207605 176441088 240156289 946977042 133416463 721098873 5 5 806744021 699586200 630510306 637827160 49223781 641709297 ...
output:
3096439746 4106290713 2653993029 4824603595 5570513606 2031887824 2044500908 1857678917 6712040279 2237593918 6479042694 5393412666 3690874076 5418938594 5513905900 5404435094 4372471266 2381297725 3430587752 4783141742 3865497483 1303747744 2692878616 3833748807 2716183054 974485573 6464787173 8839...
result:
wrong answer 1st numbers differ - expected: '3247545200', found: '3096439746'