QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420211 | #6532. Trading | DJ_F | WA | 63ms | 3644kb | C++14 | 1.3kb | 2024-05-24 15:27:54 | 2024-05-24 15:27:55 |
Judging History
answer
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5+5;
map<int, bool> mp;
struct note {
long long v;
int id;
friend bool operator < (note x, note y) {
return x.v<y.v;
}
};
vector<note> vec;
long long a[N], b[N],v, ans;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t, n, m,id,l=0, r;
cin>>t;
while(t--)
{
cin>>n;
r=n-1;
ans=0;
for(int i=0;i<n;i++)
{
cin>>v>>id;
vec.push_back({v,id});
}
sort(vec.begin(),vec.end());
// cout<<vec.front().v<<' '<<vec.front().id;
while(l<r)
{
if(vec[l].id<vec[r].id) {
ans+=(vec[r].v-vec[l].v)*vec[l].id;
vec[r].id-=vec[l].id;
l++;
}else if(vec[l].id==vec[r].id) {
ans+=(vec[r].v-vec[l].v)*vec[l].id;
r--;l++;
} else {
ans+=(vec[r].v-vec[l].v)*vec[r].id;
vec[l].id-=vec[r].id;
r--;
}
}
vec.clear();
cout<<ans<<'\n';
}
}
/*
for(int i=0;i<n;i++)
8000000000 1000000000000000000
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 63ms
memory: 3640kb
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:
974212656325 0 0 118545432988 0 0 0 0 0 0 0 33190535388 8642543756 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer 2nd numbers differ - expected: '422801098045', found: '0'