結果

問題 No.1012 荷物収集
ユーザー okok
提出日時 2020-03-20 22:02:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 88,332 KB
実行使用メモリ 6,332 KB
最終ジャッジ日時 2023-08-21 16:38:28
合計ジャッジ時間 5,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 48 ms
6,132 KB
testcase_05 AC 48 ms
6,232 KB
testcase_06 AC 47 ms
6,132 KB
testcase_07 AC 48 ms
6,216 KB
testcase_08 AC 46 ms
6,176 KB
testcase_09 AC 47 ms
6,324 KB
testcase_10 AC 48 ms
6,192 KB
testcase_11 AC 47 ms
6,240 KB
testcase_12 AC 46 ms
6,332 KB
testcase_13 AC 48 ms
6,236 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 44 ms
4,860 KB
testcase_25 AC 57 ms
5,608 KB
testcase_26 AC 30 ms
4,380 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 54 ms
5,616 KB
testcase_29 AC 31 ms
4,656 KB
testcase_30 AC 57 ms
5,680 KB
testcase_31 AC 27 ms
4,380 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 33 ms
4,384 KB
testcase_34 AC 34 ms
4,612 KB
testcase_35 AC 47 ms
5,184 KB
testcase_36 AC 34 ms
4,380 KB
testcase_37 AC 29 ms
4,672 KB
testcase_38 AC 47 ms
5,216 KB
testcase_39 AC 21 ms
4,376 KB
testcase_40 AC 25 ms
4,380 KB
testcase_41 AC 62 ms
5,912 KB
testcase_42 AC 31 ms
4,380 KB
testcase_43 AC 40 ms
4,920 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

#define x first
#define w second

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, Q, sum2 = 0;
	int sumw1 = 0, sumw2 = 0;
	vector<pair<int,int>> in;
	vector<pair<int,int>> X;
	
	cin>>N>>Q;
	
	in.resize(N);
	X.resize(Q);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].x>>in[i].w;
		sum2 += in[i].x * in[i].w;
		sumw2 += in[i].w;
	}
	
	sort(in.begin(), in.end());
	
	for(int i = 0; i < Q; i++){
		cin>>X[i].first;
		X[i].second = i;
	}
	
	sort(X.begin(), X.end());
	
	
	for(int i = 0, j = 0, con = 0, sum = 0, con2 = N; i < Q; i++){
		for(; j < N; j++){
			if(in[j].x >= X[i].first) break;
			con++;
			con2--;
			sumw2 -= in[j].w;
			sumw1 += in[j].w;
			sum2 -= in[j].x * in[j].w;
			sum += in[j].x * in[j].w;
		}
		X[i].first = (X[i].first * sumw1 - sum) + (sum2 - X[i].first * sumw2);
		
		swap(X[i].first, X[i].second);
	}
	
	sort(X.begin(), X.end());
	
	for(int i = 0; i < Q; i++){
		cout<<X[i].second<<endl;
	}
	
	return 0;
}
0