結果

問題 No.1012 荷物収集
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2020-03-20 23:19:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,720 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 173,920 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-08-21 23:40:28
合計ジャッジ時間 10,010 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 227 ms
6,220 KB
testcase_05 AC 228 ms
6,216 KB
testcase_06 AC 230 ms
6,340 KB
testcase_07 AC 227 ms
6,216 KB
testcase_08 AC 224 ms
6,172 KB
testcase_09 AC 229 ms
6,160 KB
testcase_10 AC 228 ms
6,340 KB
testcase_11 AC 227 ms
6,172 KB
testcase_12 AC 229 ms
6,208 KB
testcase_13 AC 229 ms
6,280 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n,q;
    cin>>n>>q;
    vector<pair<int,int>>v(n);
    REP(i,n) {
        cin>>v[i].first>>v[i].second;
    }
    sort(ALL(v));
    vector<int>d(n);
    REP(i,n) d[i]=v[i].first;
    vector<int>rui(n+1,0);
    for (int i = 1; i <= n; i++)
    {
        rui[i]=rui[i-1]+v[i-1].second;
    }
    //show(rui);
    int c3 = v[n/2].first;
    int c1=v[0].first;
    int c2=v[n-1].first;
    int cnt1=0;
    for (int i = 0; i < n; i++)
    {
        cnt1+=v[i].second*(v[i].first - c1);
    }
    int cnt2 = 0;
    for (int i = 0; i < n; i++)
    {
        cnt2 += v[i].second * abs(v[i].first - c2);
    }
    int cnt3=0;
    for (int i = 0; i < n; i++)
    {
        cnt3 += v[i].second * abs(v[i].first - c3);
    }
    
   // cerr<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;

    for (int i = 0; i < q; i++)
    {
        int x;
        cin>>x;
        if(x<=c1){
            cout << (rui[n] - rui[0]) * abs(x - c1) + cnt1 << endl;
        }
        else if (x>=c2){
            cout<<(rui[n]-rui[0])*(x-c2)+ cnt2<<endl;
        } 
        else{
            int l=lower_bound(ALL(d),x) - d.begin();
          //  cerr << (rui[l] - rui[0]) * (x - c3) << endl;
         // cerr<<l<<endl;
            cout << cnt3 + (rui[l] - rui[0])*(x-c3)+(rui[n]-rui[l])*(c3-x) <<endl;
        }
    }
    

    return 0;
}
0