#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#define PII pair<int,int>
#define PID pair<int,double>
#define fi first
#define se second
#define mp make_pair
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){	if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return x*f;
}
inline void print(int x){
	if(x<0) x=-x,putchar('-');
	if(x>=10) print(x/10);
	putchar(x%10+48);
}
int k;
int n,m;
int a[100010];
PII as[100010];
vector<PII> add[100010];
vector<PID>mul;
bool cmp(PID x,PID y){
	return x.se>y.se;
}
bool cm1(PII x,PII y){
	return x.fi>y.fi;
}
int main(){
	k=read(),n=read(),m=read();
	for(int i=1;i<=k;++i) a[i]=read();
	for(int i=1;i<=n;++i){
		int op=read(),pos=read(),v=read();
		switch(op){
			case 1:{
				as[pos]=max(as[pos],mp(v,i));
				break;
			}
			case 2:{
				add[pos].emplace_back(v,i+n);
				break;
			}
			case 3:{
				mul.emplace_back(i+n+n,1.0*v);
				break;
			}
		}
	}
	for(int i=1;i<=k;++i) if(as[i].fi>a[i]) add[i].emplace_back(as[i].fi-a[i],as[i].se);
	for(int i=1;i<=k;++i){
		sort(add[i].begin(),add[i].end(),cm1);
		double s=1.0*a[i];
		for(auto it:add[i]){
			mul.emplace_back(it.se,(s+it.fi)/s);
			s+=it.fi;
		}
	}
	sort(mul.begin(),mul.end(),cmp);
	int ans=min(m,(int)mul.size());
	print(ans);
	putchar('\n');
	sort(mul.begin(),mul.begin()+ans);
	int cnt=1;
	for(auto it:mul){
		if(cnt>ans) break ;
		while(it.fi>n) it.fi-=n;
		++cnt;print(it.fi);putchar(' ');
	}
	putchar('\n');
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))
using namespace std;

typedef long long li;
typedef unsigned long long lu;
typedef double real;
typedef pair<int, int> pii;

const int inf = ~0U >> 2;
const li infl = ~0LLU >> 2;

template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }

const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

int Fix(li x) {
  x %= mod;
  if (x < 0) x += mod;
  return (int)x;
}

// ----------------------------------------

const int maxn = 1e5, maxm = 1e5, maxg = maxm;

int n, m, pay;
int ori[maxn];
int type[maxm];

struct Food {
  int id, para;
  bool operator < (const Food &r) const {
    return para > r.para;
  }
};

vector<Food> food[maxn][3];

struct Good {
  li A, B;
  int id;
  bool operator < (const Good &r) const {
    return A * r.B > r.A * B;
  }
} good[maxg];

int ng;
int ans[maxg];

void Sort(vector<Food> &A) {
  sort(A.begin(), A.end());
}

int main(void) {
  scanf("%d%d%d", &n, &m, &pay);
  for (int i = 0; i < n; ++i) scanf("%d", ori + i);
  for (int i = 0; i < m; ++i) {
    int ty, tar, b;
    scanf("%d%d%d", &ty, &tar, &b);
    --ty; --tar;
    food[tar][ty].push_back({i, b});
    type[i] = ty;
  }
  for (int x = 0; x < n; ++x) {
    if (food[x][0].size()) {
      Sort(food[x][0]);
      if (food[x][0][0].para > ori[x]) {
        food[x][1].push_back({food[x][0][0].id, food[x][0][0].para - ori[x]});
      }
      food[x][0].clear();
    }
    if (food[x][1].size()) {
      Sort(food[x][1]);
      li sum = ori[x];
      for (auto it : food[x][1]) {
        good[ng++] = {sum + it.para, sum, it.id};
        sum += it.para;
      }
      food[x][1].clear();
    }
    for (auto it : food[x][2]) {
      good[ng++] = {it.para, 1, it.id};
    }
  }
  sort(good, good + ng);
  int cnt = min(ng, pay);
  for (int i = 0; i < cnt; ++i) {
    ans[i] = good[i].id;
  }
  sort(ans, ans + cnt, [](int i, int j) { return type[i] < type[j]; } );
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; ++i) {
    printf("%d%c", ans[i] + 1, " \n"[i == cnt - 1]);
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))
using namespace std;

typedef long long li;
typedef unsigned long long lu;
typedef double real;
typedef pair<int, int> pii;

const int inf = ~0U >> 2;
const li infl = ~0LLU >> 2;

template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }

const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

int Fix(li x) {
  x %= mod;
  if (x < 0) x += mod;
  return (int)x;
}

// ----------------------------------------

const int maxn = 1e5, maxm = 1e5, maxg = maxm;

int n, m, pay;
int ori[maxn];
int type[maxm];

struct Food {
  int id, para;
  bool operator < (const Food &r) const {
    return para > r.para;
  }
};

vector<Food> food[maxn][3];

struct Good {
  li A, B;
  int id;
  bool operator < (const Good &r) const {
    return (A - B) * r.B > (r.A - r.B) * B;
  }
} good[maxg];

int ng;
int ans[maxg];

void Sort(vector<Food> &A) {
  sort(A.begin(), A.end());
}

int main(void) {
  scanf("%d%d%d", &n, &m, &pay);
  for (int i = 0; i < n; ++i) scanf("%d", ori + i);
  for (int i = 0; i < m; ++i) {
    int ty, tar, b;
    scanf("%d%d%d", &ty, &tar, &b);
    --ty; --tar;
    food[tar][ty].push_back({i, b});
    type[i] = ty;
  }
  for (int x = 0; x < n; ++x) {
    if (food[x][0].size()) {
      Sort(food[x][0]);
      if (food[x][0][0].para > ori[x]) {
        food[x][1].push_back({food[x][0][0].id, food[x][0][0].para - ori[x]});
      }
      food[x][0].clear();
    }
    if (food[x][1].size()) {
      Sort(food[x][1]);
      li sum = ori[x];
      for (auto it : food[x][1]) {
        good[ng++] = {sum + it.para, sum, it.id};
        sum += it.para;
      }
      food[x][1].clear();
    }
    for (auto it : food[x][2]) {
      good[ng++] = {it.para, 1, it.id};
    }
  }
  sort(good, good + ng);
  int cnt = min(ng, pay);
  for (int i = 0; i < cnt; ++i) {
    ans[i] = good[i].id;
  }
  sort(ans, ans + cnt, [](int i, int j) { return type[i] < type[j]; } );
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; ++i) {
    printf("%d%c", ans[i] + 1, " \n"[i == cnt - 1]);
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];

std::vector < std::pair<long double, int> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];
int tp[MAXN];
int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);
    tp[i] = ty;
    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, i);
    }
  }

  for (int i = 1; i <= k; i++) {
    if (opt[i].first > a[i]) {
      plus[i].emplace_back(opt[i].first - a[i], opt[i].second);
    }

    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    /*
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back((long double) rest[j] / rest[j - 1], (Data) {i, j});
    }
    */

    long long t = a[i];
    for (int j = 0; j < (int) plus[i].size(); j++) {
      res.emplace_back((long double) (t + plus[i][j].first) / t, plus[i][j].second);
      t += plus[i][j].first;
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  //static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    ans.push_back(res[i].second);
  }

  std::sort(ans.begin(), ans.end(), [=] (int a, int b) { return tp[a] < tp[b]; });
  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back(1.0 * rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= k; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || ((int) val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back(1.0 * rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    //if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= n; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || ((int) val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back(1.0 * rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= n; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p && val[i][p].first > val2[i][p].first) {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::sort(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<long double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back((long double) rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= k; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || ((int) val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back(1.0 * rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= k; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || ((int) val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};

std::vector < std::pair<long double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back((long double) rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty]++;
    }
  }

  for (int i = 1; i <= k; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || ((int) val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = p; j >= 0; j--) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int MAXN = 1e5 + 10;

int k, n, m;
int a[MAXN];
std::pair<long long, int> opt[MAXN];
struct Data {
  int ty;
  int val;
  bool operator < (const Data &rhs) const { return ty < rhs.ty; }
};
std::vector < std::pair<double, Data> > res;
std::vector < std::pair<long long, int> > plus[MAXN];
std::vector < std::pair<long long, int> > val[MAXN], val2[MAXN];

int main() {
  scanf("%d%d%d", &k, &n, &m);

  for (int i = 1; i <= k; i++) {
    scanf("%d", a + i);
  }

  for (int i = 1; i <= n; i++) {
    int ty, x, b;
    scanf("%d%d%d", &ty, &x, &b);

    if (ty == 1) {
      opt[x] = std::max(opt[x], {b, i});
    } else if (ty == 2) {
      plus[x].emplace_back(b, i);
    } else {
      res.emplace_back(b, (Data) {0, i} );
    }
  }

  for (int i = 1; i <= k; i++) {
    std::sort(plus[i].begin(), plus[i].end());
    std::reverse(plus[i].begin(), plus[i].end());
    static long long rest[MAXN];
    rest[0] = a[i];

    int sz = 0;
    if (!plus[i].empty()) {
      val[i].push_back(plus[i].front());
      rest[1] = a[i] + plus[i].front().first;
      for (int j = 1; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val[i].back().first;
        val[i].push_back(it);
        rest[j + 1] = a[i] + it.first;
      }
      sz = std::max(sz, (int) plus[i].size());
    }

    if (opt[i].first > a[i]) {
      val2[i].emplace_back(opt[i].first - a[i], opt[i].second);
      rest[1] = std::max(rest[1], opt[i].first);
      for (int j = 0; j < (int) plus[i].size(); j++) {
        auto it = plus[i][j];
        it.first += val2[i].back().first;
        val2[i].push_back(it);
        rest[j + 2] = std::max(rest[j + 2], a[i] + it.first);
      }
      sz = std::max(sz, (int) plus[i].size() + 1);
    }

    for (int j = 1; j <= sz; j++) {
      res.emplace_back(1.0 * rest[j] / rest[j - 1], (Data) {i, j});
    }
  }

  std::sort(res.begin(), res.end());
  std::reverse(res.begin(), res.end());
  std::vector <int> ans;
  static int maxp[MAXN];
  for (int i = 0; i < m; i++) {
    if (i == (int) res.size()) break;
    if (res[i].first < 1) break;
    auto it = res[i].second;

    if (it.ty == 0) ans.push_back(it.val);
    else {
      maxp[it.ty] = std::max(maxp[it.ty], it.val);
    }
  }

  for (int i = 1; i <= n; i++) {
    int p = maxp[i];
    if (p == 0) continue;
    p--;
    if ((int) val2[i].size() <= p || (val[i].size() > p && val[i][p].first > val2[i][p].first)) {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val[i][j].second);
      }
    } else {
      for (int j = 0; j <= p; j++) {
        ans.push_back(val2[i][j].second);
      }
    }
  }

  std::reverse(ans.begin(), ans.end());

  printf("%lu\n", ans.size());
  for (auto i: ans) {
    printf("%d ", i);
  }

  printf("\n");
}


#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int a[N],op[N],id[N];
#define pb push_back
#define pii pair<int,int>
#define pdi pair<db,int>
#define fi first
#define se second
#define mp make_pair
vector <pii> p[N][2];
vector <pdi> f;
bool vis[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int k,n,m; sc(k),sc(n),sc(m);
	for (int i=1; i<=k; i++)
		sc(a[i]);
	for (int i=1; i<=n; i++)
	{
		int op,w,x; sc(op),sc(w),sc(x); --op;
		if (op==2) f.pb (mp(x,i));
		else p[w][op].pb (mp(x,i));
		::op[i]=op;
	}
	for (int i=1; i<=k; i++)
	{
		sort (p[i][0].begin (),p[i][0].end (),[](pii A,pii B) { return A> B; });
		LL cur=a[i];
		if (p[i][0].size ()) p[i][1].pb (mp(p[i][0][0].fi-cur,p[i][0][0].se));
		sort (p[i][1].begin (),p[i][1].end (),[](pii A,pii B) { return A> B; });
		for (pii x:p[i][1])
			f.pb (mp((db)(cur+x.fi)/cur,x.se)),cur+=x.fi;
	}
	sort (f.begin (),f.end (),[](pdi A,pdi B) { return A> B; });
	int ans=0; chkmin (m,(int)f.size ());
	for (; ans< m; ans++)
		if (f[ans].fi< 1) break;
		else id[++id[0]]=f[ans].se;
	pr(ans);
	sort (id+1,id+id[0]+1,[](int A,int B) { return op[A]< op[B]; });
	for (int i=1; i<=id[0]; i++)
		print(id[i]),putchar(' ');

    return 0;
}


#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int a[N],op[N],w[N],x[N],id[N];
#define pb push_back
#define pii pair<int,int>
#define pdi pair<db,int>
#define fi first
#define se second
#define mp make_pair
vector <pii> p[N][2];
vector <pdi> f;
bool vis[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int k,n,m; sc(k),sc(n),sc(m);
	for (int i=1; i<=k; i++)
		sc(a[i]);
	for (int i=1; i<=n; i++)
	{
		int op,w,x; sc(op),sc(w),sc(x); --op;
		if (op==2) f.pb (mp(x,i));
		else p[w][op].pb (mp(x,i));
	}
	for (int i=1; i<=n; i++)
	{
		sort (p[i][0].begin (),p[i][0].end (),[](pii A,pii B) { return A> B; });
		int cur=a[i];
		if (p[i][0].size ()) p[i][1].pb (mp(p[i][0][0].fi-cur,p[i][0][0].se));
		sort (p[i][1].begin (),p[i][1].end (),[](pii A,pii B) { return A> B; });
		for (pii x:p[i][1])
			f.pb (mp((db)(cur+x.fi)/cur,x.se)),cur+=x.fi;
	}
	sort (f.begin (),f.end (),[](pdi A,pdi B) { return A> B; });
	int ans=0;
	for (; ans< m; ans++)
		if (f[ans].fi< 1) break;
		else vis[f[ans].se]=1;
	pr(ans);
	for (int i=1; i<=n; i++)
		if (vis[i]) print(i),putchar(' ');

    return 0;
}


#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int a[N],op[N],id[N];
#define pb push_back
#define pii pair<int,int>
#define pdi pair<db,int>
#define fi first
#define se second
#define mp make_pair
vector <pii> p[N][2];
vector <pdi> f;
bool vis[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int k,n,m; sc(k),sc(n),sc(m);
	for (int i=1; i<=k; i++)
		sc(a[i]);
	for (int i=1; i<=n; i++)
	{
		int op,w,x; sc(op),sc(w),sc(x); --op;
		if (op==2) f.pb (mp(x,i));
		else p[w][op].pb (mp(x,i));
		::op[i]=op;
	}
	for (int i=1; i<=n; i++)
	{
		sort (p[i][0].begin (),p[i][0].end (),[](pii A,pii B) { return A> B; });
		int cur=a[i];
		if (p[i][0].size ()) p[i][1].pb (mp(p[i][0][0].fi-cur,p[i][0][0].se));
		sort (p[i][1].begin (),p[i][1].end (),[](pii A,pii B) { return A> B; });
		for (pii x:p[i][1])
			f.pb (mp((db)(cur+x.fi)/cur,x.se)),cur+=x.fi;
	}
	sort (f.begin (),f.end (),[](pdi A,pdi B) { return A> B; });
	int ans=0;
	for (; ans< m; ans++)
		if (f[ans].fi< 1) break;
		else id[++id[0]]=f[ans].se;
	pr(ans);
	sort (id+1,id+id[0]+1,[](int A,int B) { return op[A]< op[B]; });
	for (int i=1; i<=id[0]; i++)
		print(id[i]),putchar(' ');

    return 0;
}


#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int a[N],op[N],id[N];
#define pb push_back
#define pii pair<int,int>
#define pdi pair<db,int>
#define fi first
#define se second
#define mp make_pair
vector <pii> p[N][2];
vector <pdi> f;
bool vis[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int k,n,m; sc(k),sc(n),sc(m);
	for (int i=1; i<=k; i++)
		sc(a[i]);
	for (int i=1; i<=n; i++)
	{
		int op,w,x; sc(op),sc(w),sc(x); --op;
		if (op==2) f.pb (mp(x,i));
		else p[w][op].pb (mp(x,i));
		::op[i]=op;
	}
	for (int i=1; i<=k; i++)
	{
		sort (p[i][0].begin (),p[i][0].end (),[](pii A,pii B) { return A> B; });
		int cur=a[i];
		if (p[i][0].size ()) p[i][1].pb (mp(p[i][0][0].fi-cur,p[i][0][0].se));
		sort (p[i][1].begin (),p[i][1].end (),[](pii A,pii B) { return A> B; });
		for (pii x:p[i][1])
			f.pb (mp((db)(cur+x.fi)/cur,x.se)),cur+=x.fi;
	}
	sort (f.begin (),f.end (),[](pdi A,pdi B) { return A> B; });
	int ans=0; chkmin (m,(int)f.size ());
	for (; ans< m; ans++)
		if (f[ans].fi< 1) break;
		else id[++id[0]]=f[ans].se;
	pr(ans);
	sort (id+1,id+id[0]+1,[](int A,int B) { return op[A]< op[B]; });
	for (int i=1; i<=id[0]; i++)
		print(id[i]),putchar(' ');

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

struct fraction
{
	ll a, b;
	fraction(ll A = 0, ll B = 1)
	{
		a = A;
		b = B;
		ll gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
	}
};

bool cmp(pair<fraction, int> X, pair<fraction, int> Y)
{
	if (X.ff.a == Y.ff.a && X.ff.b == Y.ff.b)
		return (X.ss < Y.ss);
	fraction x = X.ff, y = Y.ff;
	ll gcd = __gcd(x.b, y.b);
	return (x.a * y.b / gcd < y.a * x.b / gcd);
}

int n, m, k, a[maxn], TYPE[maxn], out[maxn][3];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<fraction, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> TYPE[i] >> x >> y;
		type = TYPE[i]--;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(fraction(y, 1), i));
	}
	fori (i, 0, k)
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
	fori (i, 0, k)
	{
		sort(all(v[i]), greater<pii>());
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(fraction(sum + j.ff, sum), j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans), cmp);
	reverse(all(ans));
	cout << min(m, (int)ans.size()) << endl;
	fori (i, 0, min(m, (int)ans.size()))
		out[ans[i].ss][TYPE[ans[i].ss]] = 1;
	fori (i, 0, 3)
		fori (j, 0, maxn)
			if (out[j][i])
				cout << j + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

struct fraction
{
	ll a, b;
	fraction(ll A = 0, ll B = 1)
	{
		a = A;
		b = B;
		ll gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
	}
};

bool cmp(pair<fraction, int> X, pair<fraction, int> Y)
{
	if (X.ff.a == Y.ff.a && X.ff.b == Y.ff.b)
		return (X.ss < Y.ss);
	fraction x = X.ff, y = Y.ff;
	ll gcd = __gcd(x.b, y.b);
	return ((x.a / gcd) * y.b < (y.a / gcd) * x.b);
}

int n, m, k, a[maxn], TYPE[maxn], out[maxn][3];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<fraction, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> TYPE[i] >> x >> y;
		type = TYPE[i]--;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(fraction(y, 1), i));
	}
	fori (i, 0, k)
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
	fori (i, 0, k)
	{
		sort(all(v[i]), greater<pii>());
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(fraction(sum + j.ff, sum), j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans), cmp);
	reverse(all(ans));
	cout << min(m, (int)ans.size()) << endl;
	fori (i, 0, min(m, (int)ans.size()))
		out[ans[i].ss][TYPE[ans[i].ss]] = 1;
	fori (i, 0, 3)
		fori (j, 0, maxn)
			if (out[j][i])
				cout << j + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

struct fraction
{
	ll a, b;
	fraction(ll A = 1, ll B = 1)
	{
		a = A;
		b = B;
		ll gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
	}
};

bool cmp(pair<fraction, int> X, pair<fraction, int> Y)
{
	if (X.ff.a == Y.ff.a && X.ff.b == Y.ff.b)
		return (X.ss < Y.ss);
	fraction x = X.ff, y = Y.ff;
	ll gcd = __gcd(x.b, y.b);
	return ((x.a / gcd) * y.b < (y.a / gcd) * x.b);
}

int n, m, k, a[maxn], TYPE[maxn], out[maxn][3];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<fraction, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> TYPE[i] >> x >> y;
		type = TYPE[i]--;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(fraction(y, 1), i));
	}
	fori (i, 0, k)
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
	fori (i, 0, k)
	{
		sort(all(v[i]), greater<pii>());
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(fraction(sum + j.ff, sum), j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans), cmp);
	reverse(all(ans));
	cout << min(m, (int)ans.size()) << endl;
	fori (i, 0, min(m, (int)ans.size()))
		out[ans[i].ss][TYPE[ans[i].ss]] = 1;
	fori (i, 0, 3)
		fori (j, 0, maxn)
			if (out[j][i])
				cout << j + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

struct fraction
{
	ll a, b;
	fraction(ll A = 0, ll B = 1)
	{
		a = A;
		b = B;
		ll gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
	}
};

bool cmp(pair<fraction, int> X, pair<fraction, int> Y)
{
	if (X.ff.a == Y.ff.a && X.ff.b == Y.ff.b)
		return (X.ss < Y.ss);
	fraction x = X.ff, y = Y.ff;
	ll gcd = __gcd(x.b, y.b);
	return ((x.a / gcd) * y.b < (y.a / gcd) * x.b);
}

int n, m, k, a[maxn], TYPE[maxn], out[maxn][3];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<fraction, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> TYPE[i] >> x >> y;
		type = TYPE[i]--;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(fraction(y, 1), i));
	}
	fori (i, 0, k)
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
	fori (i, 0, k)
	{
		sort(all(v[i]), greater<pii>());
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(fraction(sum + j.ff, sum), j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans), cmp);
	reverse(all(ans));
	cout << min(m, (int)ans.size()) << endl;
	fori (i, 0, min(m, (int)ans.size()))
		out[ans[i].ss][TYPE[ans[i].ss]] = 1;
	fori (i, 0, 3)
		fori (j, 0, maxn)
			if (out[j][i])
				cout << j + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, m, k, a[maxn], TYPE[maxn], out[maxn][3];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<ld, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> TYPE[i] >> x >> y;
		type = TYPE[i]--;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(y, i));
	}
	fori (i, 0, k)
	{
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
		sort(all(v[i]));
		reverse(all(v[i]));
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(1.0 * (sum + j.ff) / sum, j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans));
	reverse(all(ans));
	m = min(m, (int)ans.size());
	cout << m << endl;
	fori (now, 0, 3)
		fori (i, 0, m)
			if (TYPE[ans[i].ss] == now)
				cout << ans[i].ss + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 1e5 + 1;
const ll inf = 2e18, mod = 1e9 + 7;

struct fraction
{
	ll a, b;
	fraction(ll A = 0, ll B = 1)
	{
		a = A;
		b = B;
		ll gcd = __gcd(a, b);
		a /= gcd;
		b /= gcd;
	}
};

bool cmp(pair<fraction, int> X, pair<fraction, int> Y)
{
	if (X.ff.a == Y.ff.a && X.ff.b == Y.ff.b)
		return (X.ss < Y.ss);
	fraction x = X.ff, y = Y.ff;
	ll gcd = __gcd(x.b, y.b);
	return (x.a * y.b / gcd < y.a * x.b / gcd);
}

int n, m, k, a[maxn];
pii SET[maxn];
vector<pii> v[maxn];
vector<pair<fraction, int> > ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	fill(SET, SET + maxn, mp(-1, -1));

	cin >> k >> n >> m;
	fori (i, 0, k)
		cin >> a[i];
	int type, x, y;
	fori (i, 0, n)
	{
		cin >> type >> x >> y;
		x--;
		if (type == 1)
			SET[x] = max(SET[x], mp(y, i));
		else if (type == 2)
			v[x].pb(mp(y, i));
		else
			ans.pb(mp(fraction(y, 1), i));
	}
	fori (i, 0, k)
		if (SET[i].ff > a[i])
			v[i].pb(mp(SET[i].ff - a[i], SET[i].ss));
	fori (i, 0, k)
	{
		sort(all(v[i]), greater<pii>());
		ll sum = a[i];
		for (pll j : v[i])
		{
			ans.pb(mp(fraction(sum + j.ff, sum), j.ss));
			sum += j.ff;
		}
	}
	sort(all(ans), cmp);
	reverse(all(ans));
	cout << min(m, (int)ans.size()) << endl;
	fori (i, 0, min(m, (int)ans.size()))
		cout << ans[i].ss + 1 << ' ';
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
const int maxn=200002;
struct frac{
	int id;
	ll a,b;
	bool operator <(const frac& rhs)const{ //(a-b)/b<(rhs.a-rhs.b)/rhs.b
		return rhs.b*(a-b)>(rhs.a-rhs.b)*b;
	}
}fr[maxn];
struct item{
	int id,op,p;
	ll x;
	bool operator <(const item & rhs)const{
		return op<rhs.op || (op==rhs.op && x>rhs.x);
	}
}a[maxn],b[maxn];
ll st[maxn];
bool have[maxn],use[maxn];
vector<int> ans;
int main(){
	init();
	int k=readint(),n=readint(),m=readint();
	for(int i=1;i<=k;i++)
		st[i]=readint();
	for(int i=1;i<=n;i++)
		a[i].op=readint(),a[i].p=readint(),a[i].x=readint(),a[i].id=i;
	sort(a+1,a+n+1);
	int cur=0,cnt=0;
	for(int i=1;i<=n;i++){
		if (a[i].op==1){
			if (!have[a[i].p]){
				have[a[i].p]=1;
				b[++cnt]=a[i];
				b[i].op=2,b[i].x-=st[b[i].p];
			}
		}else b[++cnt]=a[i];
	}
	sort(b+1,b+cnt+1);
	for(int i=1;i<=cnt;i++){
		if (b[i].op==2){
			fr[++cur]={b[i].id,st[b[i].p]+b[i].x,st[b[i].p]};
			st[b[i].p]+=b[i].x;
		}else fr[++cur]={b[i].id,b[i].x,1};
	}
	sort(fr+1,fr+cur+1);
	for(int i=1;i<=min(m,cur);i++)
		use[fr[i].id]=true;
	for(int i=1;i<=n;i++)
		if (use[a[i].id])
			ans.push_back(a[i].id);
	printf("%d\n",ans.size());
	for(auto i: ans)
		printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
const int maxn=200002;
struct frac{
	int id;
	ll a,b;
	bool operator <(const frac& rhs)const{ //(a-b)/b<(rhs.a-rhs.b)/rhs.b
		return rhs.b*(a-b)>(rhs.a-rhs.b)*b;
	}
}fr[maxn];
struct item{
	int id,op,p;
	ll x;
	bool operator <(const item & rhs)const{
		return op<rhs.op || (op==rhs.op && x>rhs.x);
	}
}a[maxn],b[maxn];
ll st[maxn];
bool have[maxn],use[maxn];
vector<int> ans;
int main(){
	init();
	int k=readint(),n=readint(),m=readint();
	for(int i=1;i<=k;i++)
		st[i]=readint();
	for(int i=1;i<=n;i++)
		a[i].op=readint(),a[i].p=readint(),a[i].x=readint(),a[i].id=i;
	sort(a+1,a+n+1);
	int cur=0,cnt=0;
	for(int i=1;i<=n;i++){
		if (a[i].op==1){
			if (!have[a[i].p] && a[i].x>st[a[i].p]){
				have[a[i].p]=1;
				b[++cnt]=a[i];
				b[cnt].op=2,b[cnt].x-=st[b[cnt].p];
			}
		}else b[++cnt]=a[i];
	}
	sort(b+1,b+cnt+1);
	for(int i=1;i<=cnt;i++){
		if (b[i].op==2){
			fr[++cur]={b[i].id,st[b[i].p]+b[i].x,st[b[i].p]};
			st[b[i].p]+=b[i].x;
		}else fr[++cur]={b[i].id,b[i].x,1};
	}
	sort(fr+1,fr+cur+1);
	for(int i=1;i<=min(m,cur);i++)
		use[fr[i].id]=true;
	for(int i=1;i<=n;i++)
		if (use[a[i].id])
			ans.push_back(a[i].id);
	printf("%d\n",ans.size());
	for(auto i: ans)
		printf("%d ",i);
}


#include <bits/stdc++.h>
using namespace std;

int k,n,m,t[100001];
double a[100001];
vector<pair<double,int>> v1[100001], v2[100001], s;
vector<int> ans[4];

int main(){
    scanf("%d%d%d",&k,&n,&m);
    for(int i=1; i<=k; i++){
        scanf("%lf",&a[i]);
    }
    for(int i=1; i<=n; i++){
        int p;
        double b;
        scanf("%d%d%lf",&t[i],&p,&b);
        if(t[i]==1){
            v1[p].push_back({b,i});
        }
        else if(t[i]==2){
            v2[p].push_back({b,i});
        }
        else{
            s.push_back({b,i});
        }
    }
    for(int i=1; i<=k; i++){
        if(!v1[i].empty()){
            sort(v1[i].begin(),v1[i].end());
            int t = v1[i].size()-1;
            if(v1[i][t].first>a[i]){
                v2[i].push_back({v1[i][t].first-a[i],v1[i][t].second});
            }
        }
        if(!v2[i].empty()){
            sort(v2[i].begin(),v2[i].end());
            for(int j=v2[i].size()-1; j>=0; j--){
                s.push_back({(v2[i][j].first+a[i])/a[i],v2[i][j].second});
                a[i] += v2[i][j].first;
            }
        }
    }
    sort(s.begin(),s.end());
    int c = min((int)(s.size()),m);
    for(int i=(int)(s.size())-1; i>=(int)(s.size())-c; i--){
        ans[t[s[i].second]].push_back(s[i].second);
    }
    printf("%d\n",c);
    for(int i=1; i<=3; i++){
        for(int j=0; j<ans[i].size(); j++){
            printf("%d ",ans[i][j]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int k,n,m,t[100001];
double a[100001];
vector<pair<double,int>> v1[100001], v2[100001], s;
vector<int> ans[4];

int main(){
    scanf("%d%d%d",&k,&n,&m);
    for(int i=1; i<=k; i++){
        scanf("%lf",&a[i]);
    }
    for(int i=1; i<=n; i++){
        int p;
        double b;
        scanf("%d%d%lf",&t[i],&p,&b);
        if(t[i]==1){
            v1[p].push_back({b,i});
        }
        else if(t[i]==2){
            v2[p].push_back({b,i});
        }
        else{
            s.push_back({b,i});
        }
    }
    for(int i=1; i<=k; i++){
        if(!v1[i].empty()){
            sort(v1[i].begin(),v1[i].end());
            int t = v1[i].size()-1;
            if(v1[i][t].first>a[i]){
                v2[i].push_back({v1[i][t].first-a[i],v1[i][t].second});
            }
        }
        if(!v2[i].empty()){
            sort(v2[i].begin(),v2[i].end());
            for(int j=v2[i].size()-1; j>=0; j--){
                s.push_back({(v2[i][j].first+a[i])/a[i],v2[i][j].second});
                a[i] += v2[i][j].first;
            }
        }
    }
    sort(s.begin(),s.end());
    int c = min((int)(s.size()),m);
    for(int i=s.size()-1; i>=s.size()-c; i--){
        ans[t[s[i].second]].push_back(s[i].second);
    }
    printf("%d\n",c);
    for(int i=1; i<=3; i++){
        for(int j=0; j<ans[i].size(); j++){
            printf("%d ",ans[i][j]);
        }
    }
    return 0;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#define R register
#define I inline
#define ll long long
using namespace std;
const int maxn=(1<<19)|1;
int n,k,m,ty,x,y;
int a[maxn],nidgd[maxn],mid[maxn];
struct node
{
	ll l,r;
	int id,type;
};
struct sss
{
	int first,second,type;
};
struct Anss
{
	int id,type;
	inline bool operator<(const Anss &b)const
	{
		return type<b.type;
	}
};
vector<Anss> ans;
vector<node> cmp;
vector<sss > t2[maxn];
I bool operator<(node a,node b)
{
	ll res=a.l*b.r-b.l*a.r;
	return res==0?a.id<b.id:res>0;
}
I bool cmp1(sss a,sss b)
{
	return a.first==b.first?a.second<b.second:a.first>b.first;
}
int main(void)
{
	scanf("%d%d%d",&n,&k,&m);
	for(R int i=1; i<=n; i++)
	{
		scanf("%d",&a[i]);
		nidgd[i]=a[i];
	}
	for(R int i=1; i<=k; i++)
	{
		scanf("%d%d%d",&ty,&x,&y);
		if(ty==1)
		{
			if(y>nidgd[x])
			{
				nidgd[x]=y;
				mid[x]=i;
			}
		}
		else if(ty==2)
		{
			t2[x].push_back((sss)
			{
				y,i,2
			});
		}
		else if(y!=1)
		{
			cmp.push_back((node)
			{
				y-1,1,i,3
			});
		}
	}
	for(R int i=1; i<=n; i++)
	{
		if(nidgd[i]>a[i])
		{
			t2[i].push_back((sss)
			{
				nidgd[i]-a[i],mid[i],1
			});
		}
	}
	for(R int i=1; i<=n; i++)
	{
		ll v=a[i];
		int kkk=(int)t2[i].size();
		sort(t2[i].begin(),t2[i].end(),cmp1);
		for(R int guoguo=0; guoguo<kkk; guoguo++)
		{
			sss p=t2[i][guoguo];
			cmp.push_back((node)
			{
				p.first,v,p.second,p.type
			});
			v+=1LL*p.first;
		}
	}
	sort(cmp.begin(),cmp.end());
	int GG=(int)cmp.size();
	GG=GG<m?GG:m;
	for(R int i=0; i<GG; i++)
	{
		ans.push_back((Anss)
		{
			cmp[i].id,cmp[i].type
		});
	}
	sort(ans.begin(),ans.end());
	int ANSWER=(int)ans.size();
	printf("%d\n",ANSWER);
	for(R int i=0; i<ANSWER; i++)
	{
		printf("%d ",ans[i].id);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m,k,a[maxn];
typedef pair<int,int> pii;
pii mx[maxn];
vector<pii>add[maxn];
typedef pair<long double,int> pli;
vector<pli> mul;
#define fi first
#define se second
signed main(){
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++){a[i]=read();mx[i]=pii(a[i],0);}
	for(int i=1;i<=m;i++){
		int op=read(),pos=read(),val=read();
		if(op==1){
			mx[pos]=max(mx[pos],pii(val,i));
		}
		if(op==2){
			add[pos].push_back(pii(val,i));
		}
		if(op==3){
			mul.push_back(pli(val,i));
		}
	}
	for(int i=1;i<=n;i++){
		if(mx[i].fi>a[i]){
			add[i].push_back(pii(mx[i].fi-a[i],mx[i].se));
		}
	}
	for(int i=1;i<=n;i++){
		sort(add[i].begin(),add[i].end(),greater<pii>());
		long long v=a[i];
		for(auto p:add[i]){
			mul.push_back(pli(1.0*(v+p.fi)/p.fi,p.se));
			v+=p.fi;
		}
	}
	sort(mul.begin(),mul.end(),greater<pli>());
	int x=min(m,(int)mul.size());
	printf("%d\n",x-1);
	for(int i=1;i<x;i++){
		printf("%d ",mul[i].se);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m,k,a[maxn];
typedef pair<int,int> pii;
pii mx[maxn];
vector<pii>add[maxn];
typedef pair<long double,int> pli;
vector<pli> mul;
int pos[maxn],op[maxn],val[maxn];
#define fi first
#define se second
bool cmp(pli a,pli b){
	return op[a.se]<op[b.se];
}
signed main(){
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++){a[i]=read();mx[i]=pii(a[i],0);}
	for(int i=1;i<=m;i++){
		op[i]=read(),pos[i]=read(),val[i]=read();
		if(op[i]==1){
			mx[pos[i]]=max(mx[pos[i]],pii(val[i],i));
		}
		if(op[i]==2){
			add[pos[i]].push_back(pii(val[i],i));
		}
		if(op[i]==3){
			mul.push_back(pli(val[i],i));
		}
	}
	for(int i=1;i<=n;i++){
		if(mx[i].fi>a[i]){
			add[i].push_back(pii(mx[i].fi-a[i],mx[i].se));
		}
	}
	for(int i=1;i<=n;i++){
		sort(add[i].begin(),add[i].end(),greater<pii>());
		long long v=a[i];
		for(auto p:add[i]){
			mul.push_back(pli(1.0*(v+p.fi)/v,p.se));
			v+=p.fi;
		}
	}
	sort(mul.begin(),mul.end(),greater<pli>());
	int x=min(k,(int)mul.size());
	sort(mul.begin(),mul.begin()+x,cmp);
	printf("%d\n",x);
	for(int i=0;i<x;i++){
		printf("%d ",mul[i].se);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m,k,a[maxn];
typedef pair<int,int> pii;
pii mx[maxn];
vector<pii>add[maxn];
typedef pair<long double,int> pli;
vector<pli> mul;
int pos[maxn],op[maxn],val[maxn];
#define fi first
#define se second
bool cmp(pli a,pli b){
	return op[a.se]<op[b.se];
}
signed main(){
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++){a[i]=read();mx[i]=pii(a[i],0);}
	for(int i=1;i<=m;i++){
		op[i]=read(),pos[i]=read(),val[i]=read();
		if(op[i]==1){
			mx[pos[i]]=max(mx[pos[i]],pii(val[i],i));
		}
		if(op[i]==2){
			add[pos[i]].push_back(pii(val[i],i));
		}
		if(op[i]==3){
			mul.push_back(pli(val[i],i));
		}
	}
	for(int i=1;i<=n;i++){
		if(mx[i].fi>a[i]){
			add[i].push_back(pii(mx[i].fi-a[i],mx[i].se));
		}
	}
	for(int i=1;i<=n;i++){
		sort(add[i].begin(),add[i].end(),greater<pii>());
		long long v=a[i];
		for(auto p:add[i]){
			mul.push_back(pli(1.0*(v+p.fi)/v,p.se));
			v+=p.fi;
		}
	}
	sort(mul.begin(),mul.end(),greater<pli>());
	int x=min(m-1,(int)mul.size());
	sort(mul.begin(),mul.begin()+x,cmp);
	printf("%d\n",x);
	for(int i=0;i<x;i++){
		printf("%d ",mul[i].se);
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct data{int w,i;};
bool operator<(const data&a,const data&b){return a.w>b.w;}
ll A[100010];
data p1[100010];
std::vector<data>p2[100010],p3;
double Ln2[100010],Ln3[100010];
int t[100010];
double W[100010];
struct cmp{bool operator()(int a,int b){return W[a]<W[b];}};
std::priority_queue<int,std::vector<int>,cmp>que;
int op[100010],ans2[100010],ans3[100010];
int main(){
	int n=gi(),k=gi(),lim=gi();
	for(int i=1;i<=n;++i)A[i]=gi();
	for(int i=1;i<=k;++i){
		int o=gi(),p=gi(),x=gi();
		op[i]=o;
		if(o==3)p3.push_back({x,i});
		else if(o==1){if(x>p1[p].w)p1[p]={x,i};}
		else p2[p].push_back({x,i});
	}
	for(int i=1;i<=n;++i)if(p1[i].w>A[i])p2[i].push_back({p1[i].w-A[i],p1[i].i});
	std::sort(p3.begin(),p3.end());
	for(int i=1;i<=std::min((int)p3.size(),lim);++i)ans3[i]=p3[i-1].i,Ln3[i]=Ln3[i-1]+log(p3[i-1].w);
	for(int i=p3.size()+1;i<=lim;++i)Ln3[i]=Ln3[i-1];
	for(int i=1;i<=n;++i){
		std::sort(p2[i].begin(),p2[i].end());
		if(!p2[i].empty())W[i]=log(A[i]+p2[i][0].w)-log(A[i]),que.push(i);
	}
	while(!que.empty()){
		static int i;
		++i;Ln2[i]=Ln2[i-1];
		int x=que.top();que.pop();
		Ln2[i]+=W[x];
		A[x]+=p2[x][t[x]].w;
		ans2[i]=p2[x][t[x]].i;
		if(++t[x]<p2[x].size())W[x]=log(A[x]+p2[x][t[x]].w)-log(A[x]),que.push(x);
		if(que.empty())while(i<=lim)++i,Ln2[i]=Ln2[i-1];
	}
	int T2,T3;double res=-1e233;
	for(int i=0;i<=lim;++i)if(Ln2[i]+Ln3[lim-i]>res)T2=i,T3=lim-i,res=Ln2[i]+Ln3[lim-i];
	while(T2&&!ans2[T2])--T2;
	while(T3&&!ans3[T3])--T3;
	std::sort(ans2+1,ans2+T2+1,[&](int a,int b){return op[a]<op[b];});
	printf("%d\n",T2+T3);
	for(int i=1;i<=T2;++i)printf("%d ",ans2[i]);
	for(int i=1;i<=T3;++i)printf("%d ",ans3[i]);
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct data{int w,i;};
bool operator<(const data&a,const data&b){return a.w>b.w;}
int a[100010];
data p1[100010];
std::vector<data>p2[100010],p3;
double Ln2[100010],Ln3[100010];
int t[100010],W[100010];
struct cmp{bool operator()(int a,int b){return W[a]<W[b];}};
std::priority_queue<int,std::vector<int>,cmp>que;
int op[100010],ans2[100010],ans3[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),k=gi(),lim=gi();
	for(int i=1;i<=n;++i)a[i]=gi();
	for(int i=1;i<=k;++i){
		int o=gi(),p=gi(),x=gi();
		op[i]=o;
		if(o==3)p3.push_back({x,i});
		else if(o==1){if(x>p1[p].w)p1[p]={x,i};}
		else p2[p].push_back({x,i});
	}
	for(int i=1;i<=n;++i)if(p1[i].w>a[i])p2[i].push_back({p1[i].w-a[i],p1[i].i});
	std::sort(p3.begin(),p3.end());
	for(int i=1;i<=std::min((int)p3.size(),lim);++i)ans3[i]=p3[i-1].i,Ln3[i]=Ln3[i-1]+log(p3[i-1].w);
	for(int i=p3.size()+1;i<=lim;++i)Ln3[i]=Ln3[i-1];
	for(int i=1;i<=n;++i){
		std::sort(p2[i].begin(),p2[i].end());
		if(!p2[i].empty())W[i]=p2[i][0].w,que.push(i);
	}
	while(!que.empty()){
		static int i;
		++i;Ln2[i]=Ln2[i-1];
		int x=que.top();que.pop();
		Ln2[i]+=log(W[x]);
		ans2[i]=p2[x][t[x]].i;
		if(++t[x]<p2[x].size())W[x]=p2[x][t[x]].w,que.push(x);
		if(que.empty())while(i<=lim)++i,Ln2[i]=Ln2[i-1];
	}
	int T2,T3;double res=-1e233;
	for(int i=0;i<=lim;++i)if(Ln2[i]+Ln3[lim-i]>res)T2=i,T3=lim-i,res=Ln2[i]+Ln3[lim-i];
	while(T2&&!ans2[T2])--T2;
	while(T3&&!ans3[T3])--T3;
	std::sort(ans2+1,ans2+T2+1,[&](int a,int b){return op[a]<op[b];});
	printf("%d\n",T2+T3);
	for(int i=1;i<=T2;++i)printf("%d ",ans2[i]);
	for(int i=1;i<=T3;++i)printf("%d ",ans3[i]);
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct data{int w,i;};
bool operator<(const data&a,const data&b){return a.w>b.w;}
ll A[100010];
data p1[100010];
std::vector<data>p2[100010],p3;
double Ln2[100010],Ln3[100010];
int t[100010];
double W[100010];
struct cmp{bool operator()(int a,int b){return W[a]<W[b];}};
std::priority_queue<int,std::vector<int>,cmp>que;
int op[100010],ans2[100010],ans3[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),k=gi(),lim=gi();
	for(int i=1;i<=n;++i)A[i]=gi();
	for(int i=1;i<=k;++i){
		int o=gi(),p=gi(),x=gi();
		op[i]=o;
		if(o==3)p3.push_back({x,i});
		else if(o==1){if(x>p1[p].w)p1[p]={x,i};}
		else p2[p].push_back({x,i});
	}
	for(int i=1;i<=n;++i)if(p1[i].w>A[i])p2[i].push_back({p1[i].w-A[i],p1[i].i});
	std::sort(p3.begin(),p3.end());
	for(int i=1;i<=std::min((int)p3.size(),lim);++i)ans3[i]=p3[i-1].i,Ln3[i]=Ln3[i-1]+log(p3[i-1].w);
	for(int i=p3.size()+1;i<=lim;++i)Ln3[i]=Ln3[i-1];
	for(int i=1;i<=n;++i){
		std::sort(p2[i].begin(),p2[i].end());
		if(!p2[i].empty())W[i]=log(A[i]+p2[i][0].w)-log(A[i]),que.push(i);
	}
	while(!que.empty()){
		static int i;
		++i;Ln2[i]=Ln2[i-1];
		int x=que.top();que.pop();
		Ln2[i]+=W[x];
		A[x]+=p2[x][t[x]].w;
		ans2[i]=p2[x][t[x]].i;
		if(++t[x]<p2[x].size())W[x]=log(A[x]+p2[x][t[x]].w)-log(A[x]),que.push(x);
		if(que.empty())while(i<=lim)++i,Ln2[i]=Ln2[i-1];
	}
	int T2,T3;double res=-1e233;
	for(int i=0;i<=lim;++i)if(Ln2[i]+Ln3[lim-i]>res)T2=i,T3=lim-i,res=Ln2[i]+Ln3[lim-i];
	while(T2&&!ans2[T2])--T2;
	while(T3&&!ans3[T3])--T3;
	std::sort(ans2+1,ans2+T2+1,[&](int a,int b){return op[a]<op[b];});
	printf("%d\n",T2+T3);
	for(int i=1;i<=T2;++i)printf("%d ",ans2[i]);
	for(int i=1;i<=T3;++i)printf("%d ",ans3[i]);
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db long double

using namespace std;
const int N=1e5+10;
int rd()
{
	int x=0,w=1;char ch=0;
	while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*w;
}
struct xzz
{
	db dt;
	int i;
	bool operator < (const xzz &bb) const {return dt>bb.dt;}
}an[N];
int n,m,a[N],kk,tp,co[N],mx[N][2];
bool cmp(xzz aa,xzz bb){return co[aa.i]<co[bb.i];}
vector<xzz> adn[N];

int main()
{
    ///wdnmd
	n=rd(),m=rd(),kk=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	for(int i=1;i<=m;++i)
	{
		int op=rd(),x=rd(),y=rd();
		co[i]=op;
		if(op==1)
		{
			if(mx[x][0]<y)
				mx[x][0]=y,mx[x][1]=i;
		}
		else if(op==2) adn[x].push_back((xzz){y,i});
		else an[++tp]=(xzz){log(y),i};
	}
	for(int i=1;i<=n;++i)
		if(mx[i][0]>a[i]) adn[i].push_back((xzz){mx[i][0]-a[i],mx[i][1]});
	for(int i=1;i<=n;++i)
	{
		sort(adn[i].begin(),adn[i].end());
		int nn=adn[i].size();
		LL sm=a[i];
		for(int j=0;j<nn;++j)
		{
			an[++tp]=(xzz){log(sm+adn[i][j].dt)-log(sm),adn[i][j].i};
			sm+=(LL)adn[i][j].dt;
		}
	}
	sort(an+1,an+tp+1);
	while(tp>kk) --tp;
	printf("%d\n",tp);
	sort(an+1,an+tp+1,cmp);
	for(int i=1;i<=tp;++i) printf("%d ",an[i].i);
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,int> pli;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
struct frac{
	ll a,b;	int id; // 1 + a / b;
	inline void set(ll x,ll y,int i){
		ll g=__gcd(x,y);
		a=x/g,b=y/g,id=i;
	}
	friend bool operator < (frac x,frac y){
		return x.a*y.b>x.b*y.a;
	}
}x[N];
ll fir[N],p[N],a[N],t[N],k[N],b[N];
int n,Q,m,cnt;
vi add[N],ans;

int main(){
	read(n),read(Q),read(m);
	rep(i,1,n)read(a[i]),fir[i]=a[i];
	rep(i,1,Q){
		read(t[i]),read(k[i]),read(b[i]);
		if(t[i]==1){
			if(b[i]>fir[k[i]]){
				fir[k[i]]=b[i];
				p[k[i]]=i;
			}
		}
		else if(t[i]==2){
			add[k[i]].pb(i);
		}
		else{
			x[++cnt].set(b[i]-1,1,i);
		}
	}
	rep(i,1,n){
		if(p[i]){
			b[p[i]]=fir[i]-a[i];
			add[i].pb(p[i]);
		}
		sort(add[i].begin(),add[i].end(),[&](int x,int y){
			return b[x]>b[y];
		});
		for(auto t:add[i]){
			x[++cnt].set(b[t],a[i],t);
			a[i]+=b[t];
		}
	}
	sort(x+1,x+cnt+1);
	rep(i,1,min(cnt,m)) ans.pb(x[i].id);
	sort(ans.begin(),ans.end(),[&](int x,int y){
		return t[x]<t[y];
	});
	printf("%d\n",(int)ans.size());
	for(auto x:ans)printf("%d ",x);
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int s,z,id;
	double val;
}t[N],r[N],c[N];
int n,m,k,ct,lt,num,l[N];
double d[N];
bool cmp1(node a,node b)
{
	return a.val>b.val;
}
bool cmp2(node a,node b)
{
	return a.s<b.s;
}
int main()
{
	scanf("%d%d%d",&k,&n,&m);
	for(int i=1;i<=k;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=n;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			if(t[x].val<rs)
			{
				t[x].s=opt;
				t[x].id=i;
				t[x].val=rs;
			}
		}
		if(opt==2)
		{
			r[++lt].z=x;
			r[lt].s=opt;
			r[lt].id=i;
			r[lt].val=rs;
		}
		if(opt==3)
		{
			c[++ct].s=opt;
			c[ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=k;i++)
	{
		if(t[i].val>d[i])
		{
			r[++lt].z=i;
			r[lt].s=t[i].s;
			r[lt].id=t[i].id;
			r[lt].val=t[i].val-d[i];
		}
	}
	sort(r+1,r+lt+1,cmp1);
	for(int i=1;i<=lt;i++)
	{
		c[++ct].s=r[i].s;
		c[ct].id=r[i].id;
		c[ct].val=(d[r[i].z]+r[i].val)/d[r[i].z];
		d[r[i].z]+=r[i].val;
	}
	sort(c+1,c+ct+1,cmp1);
	for(int i=1;i<=ct;i++)
	{
		if(i>m||c[i].val<=1) break;
		num=i;
	}
	printf("%d\n",num);
	sort(c+1,c+num+1,cmp2);
	for(int i=1;i<=num;i++) printf("%d ",c[i].id);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N],ds[N],s[5],ans[5][N];
double d[N];
map< int,node > r[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		ds[i]=opt;
		if(opt==1)
		{
			if(t[x].val<rs)
			{
				t[x].id=i;
				t[x].val=rs;
			}
		}
		if(opt==2)
		{
			r[x][++l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k)
		{
			num=k;
			break;
		}
		if(c[i].val<=1)
		{
			num=i-1;
			break;
		}
		num=i;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++) ans[ds[c[i].id]][++s[ds[c[i].id]]]=c[i].id;
	for(int i=1;i<=3;i++)
	  for(int j=1;j<=s[i];j++)
	    printf("%d ",ans[i][j]);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N],ans[N];
double d[N];
map< int,node > r[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			if(t[x].val<rs)
			{
				t[x].id=i;
				t[x].val=rs;
			}
		}
		if(opt==2)
		{
			r[x][++l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k)
		{
			num=k;
			break;
		}
		if(c[i].val<=1)
		{
			num=i-1;
			break;
		}
		num=i;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++) ans[i]=c[i].id;
	sort(ans+1,ans+num+1);
	for(int i=1;i<=num;i++) printf("%d ",ans[i]);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N],ans[N];
double d[N];
map< int,node > r[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			t[x].id=i;
			t[x].val=max(t[x].val,rs);
		}
		if(opt==2)
		{
			r[x][++l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k)
		{
			num=k;
			break;
		}
		if(c[i].val<=1)
		{
			num=i-1;
			break;
		}
		num=i;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++) ans[i]=c[i].id;
	sort(ans+1,ans+num+1);
	for(int i=1;i<=num;i++) printf("%d ",ans[i]);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N],ans[N];
double d[N];
map< int,node > r[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			t[x].id=i;
			t[x].val=max(t[x].val,rs);
		}
		if(opt==2)
		{
			r[x][++l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k)
		{
			num=k;
			break;
		}
		if(c[i].val<=1)
		{
			num=i-1;
			break;
		}
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++) ans[i]=c[i].id;
	sort(ans+1,ans+num+1);
	for(int i=1;i<num;i++) printf("%d ",ans[i]);
	printf("%d\n",ans[num]);
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int s,id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N],ans[N];
int n,m,k,ct,num,l[N],ds[N];
double d[N];
map< int,node > r[N];
bool cmp(node a,node b)
{
	return a.s<b.s;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		ds[i]=opt;
		if(opt==1)
		{
			if(t[x].val<rs)
			{
				t[x].s=opt;
				t[x].id=i;
				t[x].val=rs;
			}
		}
		if(opt==2)
		{
			r[x][++l[x]].s=opt;
			r[x][l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].s=opt;
			c[ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].s=t[i].s;
			r[i][l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].s=r[i][j].s;
			c[ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k||c[i].val<=1) break;
		num=i;
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
	{
		ans[i].s=c[i].s;
		ans[i].id=c[i].id;
	}
	sort(ans+1,ans+num+1,cmp);
	for(int i=1;i<=num;i++) printf("%d ",ans[i].id);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int s,id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N];
double d[N];
map< int,node > r[N];
bool cmp(node a,node b)
{
	return a.s<b.s;
}
int main()
{
	scanf("%d%d%d",&k,&n,&m);
	for(int i=1;i<=k;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=n;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			if(t[x].val<rs)
			{
				t[x].s=opt;
				t[x].id=i;
				t[x].val=rs;
			}
		}
		if(opt==2)
		{
			r[x][++l[x]].s=opt;
			r[x][l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].s=opt;
			c[ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=k;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].s=t[i].s;
			r[i][l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].s=r[i][j].s;
			c[ct].id=r[i][j].id;
			c[ct].val=(d[i]+r[i][j].val)/d[i];
			d[i]+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>m||c[i].val<1) break;
		num=i;
	}
	printf("%d\n",num);
	sort(c+1,c+num+1,cmp);
	for(int i=1;i<=num;i++) printf("%d ",c[i].id);
	printf("\n");
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#define LL long long
using namespace std;
const int N=1e5+5;
struct node
{
	int id;
	double val;
	bool operator < (const node &a)
	{
		return val>a.val;
	}
}c[N],t[N];
int n,m,k,ct,num,l[N],ans[N];
double d[N];
map< int,node > r[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&d[i]);
	for(int i=1;i<=m;i++)
	{
		int opt,x;
		double rs;
		scanf("%d%d%lf",&opt,&x,&rs);
		if(opt==1)
		{
			t[x].id=i;
			t[x].val=max(t[x].val,rs);
		}
		if(opt==2)
		{
			r[x][++l[x]].id=i;
			r[x][l[x]].val=rs;
		}
		if(opt==3)
		{
			c[++ct].id=i;
			c[ct].val=rs;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i].val>d[i])
		{
			r[i][++l[i]].id=t[i].id;
			r[i][l[i]].val=t[i].val-d[i];
		}
		double res=d[i];
		for(int j=1;j<=l[i];j++)
		{
			c[++ct].id=r[i][j].id;
			c[ct].val=(res+r[i][j].val)/res;
			res+=r[i][j].val;
		}
	}
	sort(c+1,c+ct+1);
	for(int i=1;i<=ct;i++)
	{
		if(i>k)
		{
			num=k;
			break;
		}
		if(c[i].val<=1)
		{
			num=i-1;
			break;
		}
	}
	printf("%d\n",num);
	for(int i=1;i<=num;i++) ans[i]=c[i].id;
	sort(ans+1,ans+num+1);
	for(int i=1;i<=num;i++) printf("%d ",ans[i]);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
#define cs const
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
int read(){
	int cnt=0, f=1; char ch=0;
	while(!isdigit(ch)){ ch=getchar(); if(ch=='-') f=-1; }
	while(isdigit(ch)) cnt=cnt*10+(ch-'0'), ch=getchar();
	return cnt*f;
}
cs int N = 1e5 + 50;
typedef double db;
typedef pair<int,int> pi;
int n, m, k, a[N], opt[N];
vector<pi> G[3][N];
struct data{ double mt; int c; };
data d[N]; int ct;
int main(){
//	freopen("1.in","r",stdin);
	n=read(), m=read(), k=read();
	for(int i=1; i<=n; i++) a[i]=read();
	for(int i=1; i<=m; i++){
		int op=read()-1, x=read(), v=read();
		G[op][x].pb(pi(v,i)); opt[i]=op;
	}
	for(int i=1; i<=n; i++){
		sort(G[0][i].begin(),G[0][i].end());
		sort(G[1][i].begin(),G[1][i].end());
		if(G[0][i].size())
			G[1][i].pb(pi(G[0][i].back().fi-a[i],G[0][i].back().se));
		reverse(G[1][i].begin(),G[1][i].end()); ll x = a[i];
		for(auto t : G[1][i]){
			db coe = 1.0 * t.fi / x;
			d[++ct] = (data){coe,t.se}, x+=t.fi;
		} for(auto t : G[2][i]) d[++ct] = (data){t.fi-1,t.se};
	}
	sort(d+1, d+ct+1,[](cs data &i, cs data &j){ return i.mt>j.mt; });
	k=min(k,ct); cout<<k<<'\n';
	static vector<int> as[3];
	for(int i=1; i<=k; i++) as[opt[d[i].c]].pb(d[i].c);
	for(int i=0; i<3; i++) for(int c : as[i]) cout << c << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 5;

struct Node
{
    double d; int p, op;
} t[N];

bool cmp(Node x, Node y)
{
    return x.d > y.d;
}

vector<Node> ad[N], mu;
vector<int> ans[3];

int a[N];
int n, m, k;

int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), t[i].d = a[i];
    for (int i = 1; i <= m; i++)
    {
        int op, p; double d;
        scanf("%d%d%lf", &op, &p, &d);
        if (op == 1) if (d > t[p].d) t[p] = {d, i, 0};
        if (op == 2) ad[p].push_back({d, i, 1});
        if (op == 3) mu.push_back({d, i, 2});
    }
    for (int i = 1; i <= n; i++)
    {
        if (t[i].p) ad[i].push_back({t[i].d - a[i], t[i].p});
        sort(ad[i].begin(), ad[i].end(), cmp);
        double s, ls = a[i];
        // printf("%d\n", ad[i].size());
        for (auto x : ad[i]) s = ls + x.d, x.d = s / ls, mu.push_back(x), ls = s;
    }
    sort(mu.begin(), mu.end(), cmp);
    k = min(k, (int)mu.size());
    printf("%d\n", k);
    for (int i = 0; i < k; i++) ans[mu[i].op].push_back(mu[i].p);
    for (int i = 0; i < 3; i++)
        for (int x : ans[i]) printf("%d ", x);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<bitset>
#include<map>
#include<ctime>
#include<deque>

#include<tr1/unordered_map>
using namespace std::tr1;

using namespace std;

template <typename T> void read(T &x) {
	x = 0; int f = 1; char c;
	for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f;
	for (; c >= '0' && c <= '9'; c = getchar()) x = 10 * x + c - '0' ;
	x *= f;
}
template <typename T> void write(T x){
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) { write(x); putchar('\n'); }
template <typename T> void writesn(T x) { write(x); putchar(' '); }
inline void into() { ios::sync_with_stdio(false); }

#define int long long
#define next kkksc03
#define midd ((l+r)>>1)
#define lson (o<<1)
#define rson (o<<1|1)
#define R register
#define debug puts("zxt")
#define IT set<node>::iterator

const int N = 1e5 + 10;

#define PP pair<int, int>
#define DPP pair<double, int>

int k, n, m;
int a[N], opt[N];
vector<PP > add[N];
vector<DPP > mul;
vector<int> ans;
PP pos[N];

inline bool cmp1(PP a, PP b)
{
	return a.first > b.first;
}

inline bool cmp2(DPP a, DPP b)
{
	return a.first > b.first;
}

inline bool cmp3(int a, int b)
{
	return opt[a] < opt[b];
}

signed main()
{
	into();
	read(k); read(n); read(m);
	for(R int i = 1; i <= k; i++) read(a[i]);
	for(R int i = 1, x, y; i <= n; i++)
	{
		read(opt[i]); read(x); read(y);
		if(opt[i] == 1) pos[x] = max(pos[x], make_pair(y, i));
		if(opt[i] == 2) add[x].push_back(make_pair(y, i));
		if(opt[i] == 3) mul.push_back(make_pair(y, i));
	}
	for(R int i = 1; i <= k; i++)
		if(pos[i].first > a[i])
			add[i].push_back(make_pair(pos[i].first - a[i], pos[i].second));
	for(R int i = 1; i <= k; i++)
	{
		sort(add[i].begin(), add[i].end(), cmp1);
		int num = a[i];
		for(auto p : add[i])
		{
			mul.push_back(make_pair(1.0 * (num + p.first) / num, p.second));
			num += p.first;
		}
	}
	sort(mul.begin(), mul.end(), cmp2);
	m = min(m, (int)mul.size());
	writeln(m);
	for(R int i = 0 ; i < m; i++) ans.push_back(mul[i].second);
	sort(ans.begin(), ans.end(), cmp3);
	for(auto x : ans) writesn(x);
	return 0;
}


#include<bits/stdc++.h>
#define cs const
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
int read(){
	int cnt=0, f=1; char ch=0;
	while(!isdigit(ch)){ ch=getchar(); if(ch=='-') f=-1; }
	while(isdigit(ch)) cnt=cnt*10+(ch-'0'), ch=getchar();
	return cnt*f;
}
cs int N = 1e5 + 50;
typedef double db;
typedef pair<int,int> pi;
int n, m, k, a[N], opt[N];
vector<pi> G[3][N];
struct data{ double mt; int c; };
data d[N]; int ct;
int main(){
//	freopen("1.in","r",stdin) 	;
	n=read(), m=read(), k=read();
	for(int i=1; i<=n; i++) a[i]=read();
	for(int i=1; i<=m; i++){
		int op=read()-1, x=read(), v=read();
		G[op][x].pb(pi(v,i)); opt[i]=op;
	}
	for(int i=1; i<=n; i++){
		sort(G[0][i].begin(),G[0][i].end());
		if(G[0][i].size()&&G[0][i].back().fi-a[i]>0)
			G[1][i].pb(pi(G[0][i].back().fi-a[i],G[0][i].back().se));
		sort(G[1][i].begin(),G[1][i].end());
		reverse(G[1][i].begin(),G[1][i].end()); ll x = a[i];
		for(auto t : G[1][i]){
			db coe = 1.0 * t.fi / x;
			d[++ct] = (data){coe,t.se}, x+=t.fi;
		} for(auto t : G[2][i]) d[++ct] = (data){t.fi-1,t.se};
	}
	sort(d+1, d+ct+1,[](cs data &i, cs data &j){ return i.mt>j.mt; });
	k=min(k,ct); cout<<k<<'\n';
	static vector<int> as[3];
	for(int i=1; i<=k; i++) as[opt[d[i].c]].pb(d[i].c);
	for(int i=0; i<3; i++) for(int c : as[i]) cout << c << " ";
	return 0;
}


#include<bits/stdc++.h>

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

struct node{
	ll opt,pl,val;
	bool operator<(const node c)const{return val>c.val;}
}a[100005];

int n,m,k,cnt;
ll s[100005],maxa[100005],cho[100005];
pii p[100005];
vector<int> ans,ans1,ans2,ans3;
vector<pii> v[100005];
pair<double,int> mx[300000];

void build(int id,int l,int r){
	if(l==r){
		if(v[l].size()) mx[id]=mp(1.0*(s[l]+v[l][v[l].size()-1].fi)/s[l],l);
		return;
	}
	int mid=(l+r)/2;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
}

void change(int id,int l,int r,int x){
	if(l==r){
		if(!v[l].size()) return;
		ans.push_back(v[l][v[l].size()-1].se);
		s[l]+=v[l][v[l].size()-1].fi;
		v[l].pop_back();
		if(v[l].size()) mx[id]=mp(1.0*(s[l]+v[l][v[l].size()-1].fi)/s[l],l);
		else mx[id]=mp(0,l);
		return;
	}
	int mid=(l+r)/2;
	if(x<=mid) change(id<<1,l,mid,x);
	else change(id<<1|1,mid+1,r,x);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
}

int main(){
	k=readint(); n=readint(); m=readint();
	for(int i=1;i<=k;i++) s[i]=readint();
	for(int i=1;i<=n;i++){
		a[i].opt=readint(),a[i].pl=readint(),a[i].val=readint();
		if(a[i].opt==2) v[a[i].pl].push_back(mp(a[i].val,i));
		if(a[i].opt==1&&chkmax(maxa[a[i].pl],a[i].val)) cho[a[i].pl]=i;
		if(a[i].opt==3) p[++cnt]=mp(a[i].val,i);
	}
	sort(p+1,p+cnt+1);
	for(int i=1;i<=k;i++) if(cho[i]&&a[cho[i]].val>s[i]) v[i].push_back(mp(a[cho[i]].val-s[i],cho[i]));
	for(int i=1;i<=k;i++) sort(v[i].begin(),v[i].end());
	build(1,1,k);
	for(int i=1;i<=m;i++){
		pair<double,int> tmp=mx[1];
		if(p[cnt].fi>tmp.fi) ans.push_back(p[cnt].se),cnt--;
		else change(1,1,k,tmp.se);
	}
	printf("%d\n",(int)ans.size());
	for(auto x:ans){
		if(a[x].opt==1) ans1.push_back(x);
		else if(a[x].opt==2) ans2.push_back(x);
		else ans3.push_back(x);
	}
	for(auto x:ans1) printf("%d ",x);
	for(auto x:ans2) printf("%d ",x);
	for(auto x:ans3) printf("%d ",x);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
#define cs const
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
int read(){
	int cnt=0, f=1; char ch=0;
	while(!isdigit(ch)){ ch=getchar(); if(ch=='-') f=-1; }
	while(isdigit(ch)) cnt=cnt*10+(ch-'0'), ch=getchar();
	return cnt*f;
}
cs int N = 1e5 + 50;
typedef double db;
typedef pair<int,int> pi;
int n, m, k, a[N];
vector<pi> G[3][N];
struct data{ double mt; int c; };
data d[N]; int ct;
int main(){
//	freopen("1.in","r",stdin);
	n=read(), m=read(), k=read();
	for(int i=1; i<=n; i++) a[i]=read();
	for(int i=1; i<=m; i++){
		int op=read()-1, x=read(), v=read();
		G[op][x].pb(pi(v,i));
	}
	for(int i=1; i<=n; i++){
		sort(G[0][i].begin(),G[0][i].end());
		sort(G[1][i].begin(),G[1][i].end());
		int dlt = G[0][i].back().fi;
		if(!G[1][i].size() || dlt > a[i] + G[1][i].back().fi)
		G[1][i].pb(pi(dlt-a[i],G[0][i].back().se));
		reverse(G[1][i].begin(),G[1][i].end()); ll x = a[i];
		for(auto t : G[1][i]){
			db coe = 1.0 * t.fi / x;
			d[++ct] = (data){coe,t.se}, x+=t.fi;
		} for(auto t : G[2][i]) d[++ct] = (data){t.fi,t.se};
	}
	sort(d+1, d+ct+1,[](cs data &i, cs data &j){
		return i.mt > j.mt;
	}); reverse(d+1,d+ct+1); m=min(m,ct);
	sort(d+1, d+m+1,[](cs data &i, cs data &j){ return i.c < j.c; });
	cout << m <<'\n';
	for(int i=1; i<=m; i++) cout << d[i].c << " ";
	return 0;
}


//ios::sync_with_stdio(false);
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
#define pa pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=100010;
LL R(){
    LL ans=0,f=1;char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
int K,n,m;
struct FS{
	LL x,y;int p,id;
	bool friend operator < (FS A,FS B){return A.x*B.y<A.y*B.x;}
};
priority_queue<FS> d;
vector<pa> v[N];
LL a[N],mx[N],pp[N];
vector<int> aq[3];
int oo[N];
void Work(int p){
	a[p]+=v[p].back().fi;
	v[p].pop_back();
	if(v[p].empty())return;
	if(v[p].back().fi>0)
		d.push((FS){v[p].back().fi,a[p],p,v[p].back().se});
}
int main(){
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	K=R();n=R();m=R();
	F(i,1,K)a[i]=R();
	F(i,1,n){
		int op=R();LL a=R(),b=R();
		oo[i]=op-1;
		if(op==1){
			if(b>=mx[i]){
				mx[i]=b;
				pp[i]=i;
			}
		}
		if(op==2)v[a].pb(mp(b,i));
		if(op==3)d.push((FS){b,1,0,i});
	}
	F(i,1,K){
		v[i].pb(mp(mx[i]-a[i],pp[i]));
		sort(v[i].begin(),v[i].end());
		if(v[i].back().fi>0)
			d.push((FS){v[i].back().fi,a[i],i,v[i].back().se});
	}
	int cc=0;
	while((!d.empty())&&cc+1<=m){
		int p=d.top().p;
		++cc;
		if(p==0){
			aq[oo[d.top().id]].pb(d.top().id);

		}
		else{
			aq[oo[d.top().id]].pb(d.top().id);
			Work(p);
		}
		d.pop();
	}
	cout<<cc;
	cout<<'\n';
	for(auto i:aq[0])cout<<i<<' ';
	for(auto i:aq[1])cout<<i<<' ';
	for(auto i:aq[2])cout<<i<<' ';
    return 0;
}


//ios::sync_with_stdio(false);
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
#define pa pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=100010;
LL R(){
    LL ans=0,f=1;char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
int K,n,m;
struct FS{
	LL x,y;int p,id;
	bool friend operator < (FS A,FS B){return A.x*B.y<A.y*B.x;}
};
priority_queue<FS> d;
vector<pa> v[N];
LL a[N],mx[N],pp[N];
vector<int> aq[3];
int oo[N];
void Work(int p){
	a[p]+=v[p].back().fi;
	v[p].pop_back();
	if(v[p].empty())return;
	if(v[p].back().fi>0)
		d.push((FS){v[p].back().fi+a[p],a[p],p,v[p].back().se});
}
int main(){
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	K=R();n=R();m=R();
	F(i,1,K)a[i]=R();
	F(i,1,n){
		int op=R();LL a=R(),b=R();
		oo[i]=op-1;
		if(op==1){
			if(b>=mx[a]){
				mx[a]=b;
				pp[a]=i;
			}
		}
		if(op==2)v[a].pb(mp(b,i));
		if(op==3)d.push((FS){b,1,0,i});
	}
	F(i,1,K){
		v[i].pb(mp(mx[i]-a[i],pp[i]));
		sort(v[i].begin(),v[i].end());
		if(v[i].back().fi>0){
			d.push((FS){v[i].back().fi+a[i],a[i],i,v[i].back().se});
			//cerr<<v[i].back().fi<<'\n';
		}
	}
	int cc=0;
	while((!d.empty())&&cc+1<=m){
		int p=d.top().p;
		++cc;
		if(p==0){
			aq[oo[d.top().id]].pb(d.top().id);
		}
		else{
			aq[oo[d.top().id]].pb(d.top().id);
			Work(p);
		}
		d.pop();
	}
	cout<<cc;
	cout<<'\n';
	for(auto i:aq[0])cout<<i<<' ';
	for(auto i:aq[1])cout<<i<<' ';
	for(auto i:aq[2])cout<<i<<' ';
    return 0;
}