QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472765 | #6532. Trading | mufeng12# | WA | 255ms | 3744kb | C++23 | 1.7kb | 2024-07-11 19:09:17 | 2024-07-11 19:09:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define maxint INT32_MAX
#define minint INT32_MIN
#define maxll INT64_MAX
#define minll INT64_MIN
#define mod 998244353
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
#pragma GCC optimize(2)
void write(int x);
ll c[120][120];
char *p1,*p2,buf[100000];
int read();
const int N=1e5+10;
int fact[N],infact[N];
struct node{
int v,n;
bool operator < (const node& b) const{
return v<b.v;
}
};
void solve(){
ll n;
cin>>n;
vector<node> a(n+1);
for(int i=1;i<=n;i++)
cin>>a[i].v>>a[i].n;
sort(a.begin()+1,a.end());
ll ans=0;
int l=1,r=n;
while(l<r){
int mins=min(a[l].n,a[r].n);
ans+=(a[r].v-a[l].v)*mins;
a[l].n-=mins,a[r].n-=mins;
if(a[l].n==0) l++;
if(a[r].n==0) r--;
}
cout<<ans<<endl;
return;
}
int main() {
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
int read()
{
int x=0,f=1;
char ch=nc();
while(ch<48||ch>57)
{
if(ch=='-')
f=-1;
ch=nc();
}
while(ch>=48&&ch<=57)
x=x*10+ch-48,ch=nc();
return x*f;
}
// ll ksm(ll a,ll b,ll mod){
// ll ans=1;
// a%=mod;
// while(b>0){
// if(b&1) ans=ans*a%mod;
// a=a*a%mod;
// b>>=1;
// }
// return ans;
// }
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
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: 255ms
memory: 3560kb
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:
-744919867 -2400664259 -1134720638 -1210578816 -1601339592 -96866416 1385928560 3938969176 1372696906 -7440491420 161170200 2008824615 -4685763516 -2776348872 0 -22761517 2255434397 -2275224070 3845990352 1846443908 5397242676 2747831516 -774885684 0 726882555 -2551834687 1629150693 -1888470433 7519...
result:
wrong answer 1st numbers differ - expected: '974212656325', found: '-744919867'