結果
| 問題 | 
                            No.1060 素敵な宝箱
                             | 
                    
| コンテスト | |
| ユーザー | 
                             momoyuu
                         | 
                    
| 提出日時 | 2023-09-24 03:41:27 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 711 bytes | 
| コンパイル時間 | 3,246 ms | 
| コンパイル使用メモリ | 260,232 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-17 03:51:34 | 
| 合計ジャッジ時間 | 4,774 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<vector<ll>> a(n,vector<ll>(m));
    for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) cin>>a[i][j];
    vector<ll> cnt(m,0);
    for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) cnt[j] += a[i][j];
    vector<ll> cost;
    for(int i = 0;i<n;i++){
        ll now = 0;
        for(int j = 0;j<m;j++) now += cnt[j] * a[i][j];
        cost.push_back(now);
    }
    ll ans = 0;
    sort(cost.rbegin(),cost.rend());
    for(int i = 0;i<cost.size();i++) {
        if(i%2==0) ans += cost[i];
        else ans -= cost[i];
    }
    cout<<ans<<endl;
}
            
            
            
        
            
momoyuu