codeforces-379B. New Year Present
5609242 | Jan 3, 2014 12:30:05 PM | 20114045007 | 379B - New Year Present | GNU C++ | Happy New Year! | 15 ms | 100 KB |
#include<stdio.h> #include<map> using namespace std; int main() { int n,a; int i,j; map<int,int>ma; scanf("%d",&n); for(i=0; i<n; i++) { scanf("%d",&a); if(a>0) ma[i]=a; } map<int ,int >::iterator it=ma.begin(),it1; i=0; while(!ma.empty()) { for(j=i; j<it->first; j++)printf("R"); for(j=it->first; j<i; j++)printf("L"); printf("P"); it->second--; i=it->first; it1=it; if(ma.size()>1&&it!=ma.begin()) it--; else if(ma.size()>1)it++; if(it1->second==0)ma.erase(it1->first); if(ma.size()==1) { it=ma.begin(); if(i!=it->first) { for(j=i; j<it->first; j++)printf("R"); for(j=it->first; j<i; j++)printf("L"); printf("P"); it->second--; } if(it->first>0) for(j=0; j<it->second; j++)printf("LRP"); else for(j=0; j<it->second; j++)printf("RLP"); break; } } printf("\n"); return 0; }