結果

問題 No.1495 パンの仕入れ
ユーザー chocoruskchocorusk
提出日時 2021-05-05 08:50:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 187,692 KB
実行使用メモリ 6,524 KB
最終ジャッジ日時 2023-10-10 00:40:09
合計ジャッジ時間 12,845 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 133 ms
4,352 KB
testcase_03 AC 136 ms
4,348 KB
testcase_04 AC 137 ms
4,376 KB
testcase_05 AC 133 ms
4,352 KB
testcase_06 AC 138 ms
4,372 KB
testcase_07 AC 132 ms
4,352 KB
testcase_08 AC 138 ms
4,352 KB
testcase_09 AC 133 ms
4,352 KB
testcase_10 AC 139 ms
4,352 KB
testcase_11 AC 141 ms
4,352 KB
testcase_12 AC 98 ms
4,348 KB
testcase_13 AC 94 ms
4,356 KB
testcase_14 AC 92 ms
4,352 KB
testcase_15 AC 92 ms
4,352 KB
testcase_16 AC 96 ms
4,352 KB
testcase_17 AC 99 ms
4,348 KB
testcase_18 AC 99 ms
4,352 KB
testcase_19 AC 102 ms
4,348 KB
testcase_20 AC 97 ms
4,352 KB
testcase_21 AC 97 ms
4,348 KB
testcase_22 AC 183 ms
6,524 KB
testcase_23 AC 181 ms
6,264 KB
testcase_24 AC 83 ms
4,352 KB
testcase_25 AC 82 ms
4,352 KB
testcase_26 AC 84 ms
4,352 KB
testcase_27 AC 88 ms
4,352 KB
testcase_28 AC 191 ms
6,220 KB
testcase_29 AC 174 ms
6,260 KB
testcase_30 AC 62 ms
4,352 KB
testcase_31 AC 65 ms
4,348 KB
testcase_32 AC 66 ms
4,376 KB
testcase_33 AC 66 ms
4,348 KB
testcase_34 AC 63 ms
4,356 KB
testcase_35 AC 94 ms
4,352 KB
testcase_36 AC 90 ms
4,348 KB
testcase_37 AC 97 ms
4,352 KB
testcase_38 AC 100 ms
4,348 KB
testcase_39 AC 102 ms
4,352 KB
testcase_40 AC 72 ms
4,352 KB
testcase_41 AC 67 ms
4,352 KB
testcase_42 AC 71 ms
4,352 KB
testcase_43 AC 66 ms
4,352 KB
testcase_44 AC 68 ms
4,352 KB
testcase_45 AC 1 ms
4,352 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int t; cin>>t;
    while(t--){
        int n, m;
        ll k;
        cin>>n>>m>>k;
        vector<ll> c(n), s(n);
        ll ans=0;
        for(int i=0; i<m; i++){
            int x;
            ll y;
            cin>>x>>y;
            x--;
            c[x]++;
            s[x]+=y;
            ans+=y*y;
        }
        ll l=-2e18, r=1e15;
        while(r-l>1){
            ll m=(l+r)/2;
            ll cnt=0;
            for(int i=0; i<n; i++){
                if(c[i]==0){
                    if(m>=0) cnt=1e18;
                }else{
                    if(m+2*s[i]+c[i]>0) cnt+=(m+2*s[i]+c[i])/(2*c[i]);
                }
            }
            if(cnt>=k) r=m;
            else l=m;
        }
        ll cnt1=0;
        for(int i=0; i<n; i++){
            if(c[i]==0) continue;
            if(r-1+2*s[i]+c[i]>0){
                ll x=(r-1+2*s[i]+c[i])/(2*c[i]);
                cnt1+=x;
                ans+=x*x*c[i]-2*s[i]*x;
            }
        }
        ans+=(k-cnt1)*r;
        cout<<ans<<endl;
    }
    return 0;
}
0