QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472696 | #6532. Trading | zzisjtu# | WA | 72ms | 3824kb | C++23 | 1.3kb | 2024-07-11 18:31:36 | 2024-07-11 18:31:39 |
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 ed
{
ll a,b;
bool operator<(const ed& t)const{
return a<t.a;
}
};
void solve()
{
int n;
cin>>n;
vector<ed>x(n+1);
for(int i=1;i<=n;i++){
cin>>x[i].a>>x[i].b;
}
sort(x.begin()+1,x.end());
// vector<vector<int>>dp(n+1);
ll ans=0;
ll sum=0;
for(int i=1,j=n;i<j;i++){
ll ans1=ans;
// cout<<i<<" "<<j<<endl;
ans1-=x[i].a*x[i].b;
sum+=x[i].b;
// cout<<ans<<" "<<sum<<" "<<x[j].b<<" ";
if(x[j].b>sum){
ans1+=x[j].a*sum;
sum=0;
x[j].b-=sum;
}
else{
ans1+=x[j].a*x[j].b;
sum-=x[j].b;
j--;
}
// cout<<ans1<<endl;
ans=max(ans,ans1);
}
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: 1ms
memory: 3620kb
input:
2 4 10 2 30 7 20 4 50 1 2 1 100 1 1000
output:
100 0
result:
ok 2 number(s): "100 0"
Test #2:
score: -100
Wrong Answer
time: 72ms
memory: 3824kb
input:
100000 8 567091 283679 875020 918237 314684 148083 456411 304598 766056 882388 135371 326501 578773 250140 221306 874117 5 126777 129517 846433 679825 649281 330021 427768 362636 390068 692169 5 657677 231119 941936 991342 901241 15133 660372 970476 698958 209343 10 478657 163635 752788 819629 82110...
output:
1281007100160 457793311338 390430341174 1478141925396 1491423573098 740205953594 198954424176 900541543854 14257598794 1455231408001 643222056804 383412680121 1554922394333 162650800998 0 829772727111 628238614871 945654447854 823130077332 1032961044536 819214004462 1252799859042 547471672972 0 9548...
result:
wrong answer 1st numbers differ - expected: '974212656325', found: '1281007100160'