Exemple #1
0
  void solve() {
    for (int i = 0; i < n; i++)
      up[i] = i;
    for (int i = 0; i < m; i++)
      left[i] = i + n;

    while (1) {
      int x = -1;
      for (int i = 0; i < m; i++)
        if (lt(b[i], 0) && (x == -1 || b[i] < b[x])) {
          x = i;
        }
      if (x == -1) break;
      int y = -1;
      for (int j = 0; j < n; j++)
        if (lt(a[x][j], 0)) {
          y = j; 
          break;
        }
      if (y == -1) {
        status = -1;
        return;
        assert(false); // no solution
      }
      pivot(x, y);
    }
    while (1) {
      int y = -1;
      for (int i = 0; i < n; i++)
          if (lt(0, c[i])  && (y == -1 || (c[i] > c[y]))) {
              y = i;
          }
      if (y == -1) break;
      
      int x = -1;
      for (int i = 0; i < m; i++) {
          if (lt(0, a[i][y])) {
              if (x == -1 || (b[i] / a[i][y] < b[x] / a[x][y])) {
                  x = i;
              } 
          }
      }
      if (y == -1) {
          status = 1;
          return;
          assert(false); // infinite solution
      }
      pivot(x, y);
    }

    res.assign(n, 0);

    for (int i = 0; i < m; i++) {
        if (left[i] < n) {
            res[left[i]] = b[i];
        }
    }
    status = 0;
  }