QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420191#6532. TradingDJ_FTL 1ms3704kbC++141.3kb2024-05-24 15:16:522024-05-24 15:16:53

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 15:16:53]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3704kb
  • [2024-05-24 15:16:52]
  • 提交

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;
    cin>>t;
    while(t--)
    {
        cin>>n;
        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;
        for(int l=0,r=n-1;l<r;)
        {
            if(vec[l].id<vec[r].id) {
                ans+=(vec[r].v-vec[l].v)*vec[l].id;
//                vec[l].id=0;
                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--;
            }
        }
        cout<<ans<<'\n';
    }
}
/*
for(int i=0;i<n;i++)
8000000000 1000000000000000000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

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
Time Limit Exceeded

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
161429665646
83496362384
329338375968
53026131357
64215336672
19592001134
55459453729
93934100
51055683478
14577196873
11885578150
9603028936
2127599579
0
5650189586
3268599335
2649011338
2006630389
1616560789
407688107
4902476801
48114095
0
48114095
34005550219
2293975507
1031469059
26...

result: