QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353923#6532. TradingqiyeRE 1ms4432kbC++171.4kb2024-03-14 19:15:302024-03-14 19:15:30

Judging History

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

  • [2024-03-14 19:15:30]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4432kb
  • [2024-03-14 19:15:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define X first
#define Y second
#pragma GCC optimize(2)

typedef long long i64;
typedef pair<int,int> pii;

const int mod=1e9+7;
i64 qpow(i64 a,i64 p){
    a%=mod;
    int res=1%mod;
    while(p>0){
        if(p&1)res=res*a%mod;
        a=a*a%mod;
        p>>=1;
    }
    return res%mod;
}

const int N=1e5+10;
i64 sum[N];
vector<int>a;

void solve(){
    a.clear();
    memset(sum,0,sizeof(sum));
    i64 n;
    cin>>n;
    i64 l,r;
    i64 amax=0,amin=1e7;
    for(int i=0;i<n;i++){
        cin>>l>>r;
        amax=max(amax,l);
        amin=min(amin,l);
        if(sum[l]==0){
            a.push_back(l);
        }
        sum[l]+=r;
    }
    if(amax==amin){
        cout<<0;
    }
    else{
        i64 ans=0;
        sort(a.begin(),a.end());
        int i=0,j=a.size()-1;
        while(i<j){
            int m=min(sum[a[i]],sum[a[j]]);
            ans+=(m*(a[j]-a[i]));
            sum[a[j]]-=m;
            sum[a[i]]-=m;
            if(sum[a[j]]==0){
                j--;
            }
            if(sum[a[i]]==0){
                i++;
            }
        }
        cout<<ans;
    }


}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T = 1;
	cin>>T;
	for(int i = 1; i <= T; i ++ ){
			solve();
			if(i != T)cout << '\n';
	}
    return 0;
}

详细

Test #1:

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

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
Runtime Error

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:


result: