Esempio n. 1
0
int main()
{
  int t,i,j,k,n,s,m;
  scanf("%d",&t);
  pii p;
  
  while(t--){
    v.clear();
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d %d",&j,&k);
      v.push_back(ii(j,0));
      v.push_back(ii(k,1));      
    }

    sort(v.begin(),v.begin()+2*n);
    s=0,m=-SENTINEL;
    for(i=0;i<2*n;i++){
      p=v[i];
      if(p.second==0)s+=1;
      else s-=1;
      m=max(m,s);
    }
    printf("%d\n",m);
  }
  return 0;
}
Esempio n. 2
0
File: b.cpp Progetto: alexkats/Code
int main ()
{
    srand (time (0));

    //freopen (NAME".in", "r", stdin);
    //freopen (NAME".out", "w", stdout);

    scanf ("%d %d", &n, &k);

    for (int i = 0; i < n; i++)
    {
        int x;
        scanf ("%d", &x);
        a.pb (mp (x, i + 1));
    }

    sort (a.begin (), a.end (), cmp);
    int curr = a [n - 1].frs - a [0].frs;

    while (curr > 1 && k > 0)
    {
        a [n - 1].frs--;
        a [0].frs++;
        ans.pb (mp (a [n - 1].snd, a [0].snd));
        k--;
        sort (a.begin (), a.end (), cmp);
        curr = a [n - 1].frs - a [0].frs;
    }

    printf ("%d %d\n", curr, (int) ans.size ());

    for (int i = 0; i < (int) ans.size (); i++)
        printf ("%d %d\n", ans [i].frs, ans [i].snd);

    return 0;
}
Esempio n. 3
0
bool findMatch(int v, int* prev, bool* visit, int hSize, const vpii& pairs) {
  if (v < 0) {
    return true;
  }
  for (int i = 0; i < hSize; i++) {
    if (visit[i] ||
        !binary_search(pairs.begin(), pairs.end(), make_pair(i, v))) {
      continue;
    }
    visit[i] = true;
    if (findMatch(prev[i], prev, visit, hSize, pairs)) {
      prev[i] = v;
      return true;
    }
  }
  return false;
}