結果
| 問題 |
No.2869 yuusaan's Knapsacks
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-31 02:10:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,316 bytes |
| コンパイル時間 | 4,617 ms |
| コンパイル使用メモリ | 257,864 KB |
| 最終ジャッジ日時 | 2025-02-24 03:28:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 6 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
template<typename T>
bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
template<typename T>
bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(15);
}
} io_setup;
int main(){
int n,m;
cin>>n>>m;
vector<int> e(n);
rep(i,0,n) cin>>e.at(i);
vector<pair<int,int>> vw(m);
for(auto&[v,w]:vw) cin>>v>>w;
ll mx=0;
vector<vector<int>> ans(n);
rep(bit,1,(1<<m)){
ll tmp=0;
rep(i,0,m) if((bit>>i)&1) tmp+=vw.at(i).first;
if(tmp<mx) continue;
vector<pair<int,int>> nw;
rep(i,0,m) if((bit>>i)&1) nw.push_back({vw.at(i).second,i});
sort(nw.begin(),nw.end());
auto ce=e;
vector<vector<int>> nans(n);
int flg=0;
while(!nw.empty()){
auto[x,i]=nw.back();
nw.pop_back();
int j=-1,d=1e9;
rep(k,0,n) if(ce.at(k)>=x){
if(chmin(d,ce.at(k)-x)) j=k;
}
if(j==-1){
flg=1;
break;
}
ce.at(j)-=x;
nans.at(j).push_back(i);
}
if(!flg) swap(ans,nans),mx=tmp;
}
cout<<mx<<"\n";
rep(i,0,n){
cout<<ans.at(i).size()<<" ";
for(auto x:ans.at(i)) cout<<x+1<<" ";
cout<<"\n";
}
}