結果
| 問題 |
No.2501 Maximum Inversion Number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-13 23:34:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,898 bytes |
| コンパイル時間 | 2,311 ms |
| コンパイル使用メモリ | 191,192 KB |
| 実行使用メモリ | 25,636 KB |
| 最終ジャッジ日時 | 2024-09-15 19:26:43 |
| 合計ジャッジ時間 | 6,127 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 10 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
30 | auto[r,l] = RL.at(i);
| ^
main.cpp:40:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
40 | auto[a,pos,start] = Q.top(); Q.pop();
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
long long N,M; cin >> N >> M;
vector<pair<long long,long long>> RL(N);
for(int i=0; i<2; i++){
for(int k=0; k<N; k++){
if(i) cin >> RL.at(k).first;
else cin >> RL.at(k).second;
}
}
sort(RL.begin(),RL.end());
long long minlen = 0,maxlen = 0;
for(int i=0; i<N; i++){
minlen += RL.at(i).second;
maxlen += RL.at(i).first;}
if(minlen > M || maxlen < M){cout << -1 << endl; continue;}
M -= minlen;
priority_queue<tuple<long long,long long,bool>,vector<tuple<long long,long long,bool>>,greater<tuple<long long,long long,bool>>> Q;
for(int i=0; i<N; i++){
auto[r,l] = RL.at(i);
Q.push({l,i,true}); Q.push({r,i,false});
}
long long back = 0;
set<int> st;
vector<long long> use(N);
for(int i=0; i<N; i++) tie(ignore,use.at(i)) = RL.at(i);
while(Q.size()){
auto[a,pos,start] = Q.top(); Q.pop();
long long add = a-back,ope = add*st.size();
if(M < ope){
add = M/st.size(); ope = add*st.size();
back += add; M -= ope;
for(auto x : st){
use.at(x) = back;
if(M){use.at(x)++; M--;}
}
break;
}
back += add; M -= ope;
if(start) st.insert(pos);
else{st.erase(pos); use.at(pos) = back;}
}
long long answer = 0,sum = 0;
for(int i=0; i<N; i++){
long long u = use.at(i);
answer += u*sum;
sum += u;
}
cout << answer << endl;
}
}