結果

問題 No.1012 荷物収集
ユーザー kotatsugame
提出日時 2020-03-24 20:29:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 76,776 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-31 16:08:59
合計ジャッジ時間 10,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,Q;
long ans[1<<17];
main()
{
	cin>>N>>Q;
	vector<pair<int,int> >A(N+Q);
	long now=0,W=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i].first>>A[i].second;
		now+=(long)A[i].first*A[i].second;
		W-=A[i].second;
	}
	for(int i=0;i<Q;i++)
	{
		cin>>A[N+i].first;
		A[N+i].second=-i;
	}
	sort(A.begin(),A.end());
	int pre=0;
	for(pair<int,int>p:A)
	{
		int x=p.first;
		now+=W*(x-pre);
		pre=x;
		if(p.second>0)
		{
			W+=p.second*2;
		}
		else
		{
			ans[-p.second]=now;
		}
	}
	for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
0