Cod sursa(job #1419392)

Utilizator ArchazeyBaltatu Andrei-Mircea Archazey Data 15 aprilie 2015 15:22:15
Problema Cuplaj maxim de cost minim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.37 kb
#include<bits/stdc++.h>
using namespace std;

struct cell
{
    int x,y,ind;
};

ifstream fin("vmin.in");
ofstream fout("vmin.out");

const int NMAX=100005;
const int MMAX=1000005;

int n,m,t[MMAX],when[MMAX],st[NMAX];
cell a[NMAX];

inline bool cmp(const cell A,const cell B)
{
    return A.x>B.x;
}

int main()
{
    int i,j,top,sol,sto,mij,dr;
    fin>>n>>m;
    for (i=1;i<=n;i++)
        {
            fin>>a[i].x>>a[i].y;
            a[i].ind=i;
        }
    for (i=1;i<=m;i++) fin>>t[i];
    sort(a+1,a+n+1,cmp);
    top=0;
    for (i=1;i<=n;i++)
        {
            while (top && a[st[top]].y>=a[i].y) top--;
            st[++top]=i;
        }
    for (i=2;i<=top;i++)
        {
            sto=1;dr=m;sol=m+1;
            while (sto<=dr)
                {
                    mij=(sto+dr)>>1;
                    if ((a[st[i]].x*t[mij]+a[st[i]].y)<(a[st[i-1]].x*t[mij]+a[st[i-1]].y))
                        {
                            sol=mij;
                            dr=mij-1;
                        }
                    else sto=mij+1;
                }
            fout<<i<<" "<<sol<<"\n";
            when[sol]=max(when[sol],i);
        }
    j=1;
    for (i=1;i<=m;i++)
        {
            j=max(j,when[i]);
            //fout<<when[i]<<" "<<j<<" ";
            fout<<a[st[j]].ind<<" ";
        }
    return 0;
}