#include #include #include #include #include #include #include #include using namespace std; ofstream fout("party.out"); ifstream fin("party.in"); clock_t tm1,tm2; float vr; struct st { int x,y,z; string path; }; struct party { int x,y; long long int n,k,p; }; struct Comp { bool operator()(const st& a,const st& b) { return a.z>b.z; } }; bool cmp(party x,party y) { if(x.ny.n)return false; if(x.k,Comp> pq; int a[256][256]; long long int r[256][256]; int d[256][256]; party b[131072]; string path[256][256]; st c[256]; int n,p,k; st s,nach; long long int mxpts=0; string mxpath; void input() { fin>>n>>p>>k; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { fin>>a[i][j]; } } fin>>nach.x>>nach.y; for(int i=1;i<=p;i++) { fin>>b[i].x>>b[i].y>>b[i].n>>b[i].p; b[i].k=b[i].n+b[i].p; d[b[i].x][b[i].y]=1; } for(int i=1;i<=k;i++) { fin>>c[i].x>>c[i].y; d[c[i].x][c[i].y]=2; } sort(b+1,b+1+p,cmp); /* for(int i=1;i<=p;i++) { fout<4.5)return; s=pq.top(); x=s.x; y=s.y; pt=s.path; pq.pop(); if(y+1<=n) { q=razt(a[x][y],a[x][y+1],cakes); // fout<q+r[x][y]) { r[x][y+1]=q+r[x][y]; s.x=x; s.y=y+1; s.z=r[x][y+1]; s.path=pt+'R'; path[s.x][s.y]=s.path; pq.push(s); } } if(y-1>=1) { q=razt(a[x][y],a[x][y-1],cakes); if(r[x][y-1]>q+r[x][y]) { r[x][y-1]=q+r[x][y]; s.x=x; s.y=y-1; s.z=r[x][y-1]; s.path=pt+'L'; path[s.x][s.y]=s.path; pq.push(s); } } if(x-1>=1) { q=razt(a[x][y],a[x-1][y],cakes); if(r[x-1][y]>q+r[x][y]) { r[x-1][y]=q+r[x][y]; s.x=x-1; s.y=y; s.z=r[x-1][y]; s.path=pt+'U'; path[s.x][s.y]=s.path; pq.push(s); } } if(x+1<=n) { q=razt(a[x][y],a[x+1][y],cakes); if(r[x+1][y]>q+r[x][y]) { r[x+1][y]=q+r[x][y]; s.x=x+1; s.y=y; s.z=r[x+1][y]; s.path=pt+'D'; path[s.x][s.y]=s.path; pq.push(s); } } } /*for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { fout<4.5)break; //fout<p)break; djikstra(s.x,s.y,0); tm2=clock()-tm1; vr=(float)tm2/CLOCKS_PER_SEC; if(vr>4.5)break; for(;pr<=p;pr++) {//fout<=mxpts) { mxpts=points; mxpath=pyt; } } int main() { tm1=clock(); // tm2=clock()-tm1; //vr=(float)tm2/CLOCKS_PER_SEC; input(); /*for(int i=1;i<=p;i++) { fout<