Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef ACMTUYO
- #define cin lala
- ifstream cin;
- #define cout coco
- ofstream cout;
- #endif
- #define forsn(i, s, n) for(int i = int(s); i < int(n); ++i)
- typedef long long int ll;
- struct paciente{
- int tipo, timeA, timeB, id, minT;
- };
- bool CompA(const paciente & a, const paciente & b) { return a.timeB > b.timeB;};
- bool CompB(const paciente & a, const paciente & b) { return a.timeA > b.timeA;};
- pair<vector<int>,vector<int> > prueba(deque<paciente> A, deque<paciente> B, int & maxT)
- {
- sort(A.begin(),A.end(),CompA);
- sort(B.begin(),B.end(),CompB);
- vector<int> rA, rB;
- int tA = 0, tB = 0;
- while(A.size() || B.size())
- {
- //cout<<A.size()<<" - "<<B.size()<<endl;
- if(tA <= tB && A.size() || B.size() == 0)
- {
- auto p = A.front();
- tA = max(tA, p.minT);
- p.minT += p.timeA;
- tA += p.timeA;
- rA.push_back(p.id);
- if(A.front().tipo == 1) B.push_back(p);
- A.pop_front();
- }
- else
- {
- auto p = B.front();
- tB = max(tB, p.minT);
- p.minT += p.timeB;
- tB+=p.timeB;
- rB.push_back(p.id);
- if(B.front().tipo == 2) A.push_back(p);
- B.pop_front();
- }
- }
- maxT = max(tA,tB);
- return {rA,rB};
- }
- paciente in[30];
- int N;
- vector<int> rA, rB;
- int bestT = 1e9;
- void Recursiva(int i, deque<paciente> & A, deque<paciente> & B)
- {
- cout<<i<<" / "<<N<<endl;
- if(i == N+1)
- {
- int t;
- pair<vector<int>,vector<int> > res = prueba(A,B,t);
- if(t < bestT) bestT = t, rA = res.first, rB = res.second;
- return;
- }
- if(in[i].tipo == 1)
- {
- A.push_back(in[i]);
- Recursiva(i+1,A,B);
- A.pop_back();
- }
- else if(in[i].tipo == 2)
- {
- B.push_back(in[i]);
- Recursiva(i+1,A,B);
- B.pop_back();
- }
- else
- {
- in[i].tipo = 1;
- A.push_back(in[i]);
- Recursiva(i+1,A,B);
- A.pop_back();
- in[i].tipo = 2;
- B.push_back(in[i]);
- Recursiva(i+1,A,B);
- B.pop_back();
- }
- }
- int main() {
- // assert(sqrte(1) == 1);
- // assert(sqrte(2) == 2);
- #ifndef ACMTUYO
- cin = ifstream("kth.in");
- cout = ofstream("kth.out");
- #endif
- cin>>N;
- cout<<"k"<<endl;
- for(int i = 1;i<=N;i++)
- {
- cin>>in[i].tipo>>in[i].timeA>>in[i].timeB;
- in[i].minT = 0;
- in[i].id = i;
- }
- cout<<"k"<<endl;
- deque<paciente> A,B;
- Recursiva(1,A,B);
- cout<<bestT<<endl;
- for(auto k : rA)cout<<k<<" ";
- cout<<endl;
- for(auto k : rB)cout<<k<<" ";
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement