Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code was writen by Alexander Dryapko (sdryapko)
- #include<sstream>
- #include<iostream>
- #include<stdio.h>
- #include<math.h>
- #include<stdlib.h>
- #include<algorithm>
- #include<vector>
- #include<map>
- #include<set>
- #include<string>
- #include<string.h>
- #define gcd(a,b) __gcd((a),(b));
- #define sqr(a) ((a)*(a))
- #define odd(a) ((a)&1)
- const int maxi=2000000000;
- const int maxq=1000000000;
- const double eps=1e-10;
- const double pi=3.1415926535897932;
- const double inf=1e+18;
- const int mo=1000000007;
- using namespace std;
- long long f[55][55][111];
- vector<long long> ansj,ansk;
- struct T {
- int x,nom;
- long long l,r;
- } a[1111];
- struct TT {
- int i,j,k;
- } p[55][55][111];
- int qi,qk,qj,n,m,fi,fj,fk;
- long long ko,kk;
- bool my(T x,T y) {
- if (x.x>y.x) return false; else return true;
- }
- int main(){
- //freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- cin>>n>>m>>ko;
- for (int i=1;i<=m;i++) cin>>a[i].l>>a[i].r>>a[i].x;
- for (int i=1;i<=m;i++) a[i].nom=i;
- sort(a+1,a+m+1,&my);
- for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) for (int k=0;k<=a[j].r-a[j].l;k++) {
- if (i==1) {
- f[i][j][k]=max(f[i][j][k],a[j].l+k);
- p[i][j][k].i=i-1;
- p[i][j][k].j=0;
- p[i][j][k].k=0;
- continue;
- }
- if ((k+a[j].l)%ko==0) {
- kk=(k+a[j].l)/ko;
- for (int jjj=1;jjj<j;jjj++) if (a[jjj].x<a[j].x&&kk>=a[jjj].l&&kk<=a[jjj].r) {
- if (f[i][j][k]<f[i-1][jjj][kk-a[jjj].l]+k+a[j].l) {
- f[i][j][k]=f[i-1][jjj][kk-a[jjj].l]+k+a[j].l;
- p[i][j][k].i=i-1;
- p[i][j][k].j=jjj;
- p[i][j][k].k=kk-a[jjj].l;
- }
- }
- }
- kk=(k+a[j].l)-ko;
- if (kk<0) continue;
- for (int jjj=1;jjj<j;jjj++) if (a[jjj].x<a[j].x&&kk>=a[jjj].l&&kk<=a[jjj].r) {
- if (f[i][j][k]<f[i-1][jjj][kk-a[jjj].l]+k+a[j].l) {
- f[i][j][k]=f[i-1][jjj][kk-a[jjj].l]+k+a[j].l;
- p[i][j][k].i=i-1;
- p[i][j][k].j=jjj;
- p[i][j][k].k=kk-a[jjj].l;
- }
- }
- // cout<<i<<' '<<j<<' '<<k<<' '<<f[i][j][k]<<endl;
- }
- long long ans=0;
- for (int j=1;j<=m;j++) for (int k=0;k<=a[j].r-a[j].l;k++) {
- // cout<<j<<' '<<k<<endl;
- // cout<<f[n][j][k]<<endl;
- if (f[n][j][k]>ans) {
- ans=f[n][j][k];
- fi=n;
- fj=j;
- fk=k;
- }
- }
- if (ans==0) {
- puts("NO");
- return 0;
- }
- while (fi) {
- ansj.push_back(fj);
- ansk.push_back(a[fj].l+fk);
- qi=fi;
- qj=fj;
- qk=fk;
- fi=p[qi][qj][qk].i;
- fj=p[qi][qj][qk].j;
- fk=p[qi][qj][qk].k;
- }
- reverse(ansj.begin(),ansj.end());
- reverse(ansk.begin(),ansk.end());
- if (ansj.size()<n) {
- puts("NO");
- return 0;
- }
- puts("YES");
- for (int i=0;i<ansj.size();i++) cout<<a[ansj[i]].nom<<' '<<ansk[i]<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement