#include #include #include using namespace std; class Flaction { public: long long a, b; int id; public: Flaction( void ) = default; Flaction( long long a, long long b, int id ) : a( a ), b( b ), id( id ) {}; int getID( void ) { return this->id; } bool operator < ( const Flaction &flac ) const { if( this->a * flac.b == flac.a * this->b ) return this->id > flac.id; else return this->a * flac.b < flac.a * this->b; } }; int main( void ) { int N, M; cin >> N >> M; vector A( N ), B( M ); for( int i = 0; i < N; i++ ) { cin >> A[i]; } for( int i = 0; i < M; i++ ) { cin >> B[i]; } priority_queue q; vector counter( N, 0 ); for( int i = 0; i < N; i++ ) { q.push( Flaction( A[i], B[0], i ) ); } Flaction max_people; for( int k = 0; k < M; k++ ) { max_people = q.top(), q.pop(); counter[max_people.getID()]++; if( counter[max_people.getID()] != M ) { q.push( Flaction( A[max_people.getID()], B[counter[max_people.getID()]], max_people.getID() ) ); } cout << max_people.getID() + 1 << endl; } return 0; }