Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream in("vase1.in");
- ofstream out("vase1.out");
- long long n,d[100001],s[100001],x,difs,difd,vas,grs,grj;
- char v;
- long long ss,sd;
- int main()
- {in>>n;
- for(int i=1;i<=n;i++)
- {
- in>>x>>v;
- if(v=='D')
- {
- d[i]=x;
- sd=sd+x;
- }
- else
- {
- ss=ss+x;
- s[i]=x;
- }
- }
- in>>vas;
- difs=(ss-sd)/2;
- out<<ss-difs<<'\n';
- difd=-difs;
- if(d[vas]!=0)
- {
- for(int i=0;i<vas;i++)grj=grj+d[i];
- grs=grj+d[vas];
- if(grj-difd<0)
- {
- if(grs-difd<=0)
- {
- out<<difd-grj<<" S"<<'\n';
- out<<difd-grs<<" S"<<'\n';
- }
- else
- {
- out<<difd-grj<<" S"<<'\n';
- out<<grs-difd<<" D"<<'\n';
- }
- }
- else
- {
- out<<grs-difd<<" D"<<'\n';
- out<<grj-difd<<" D"<<'\n';
- }
- }
- else
- {
- for(int i=1;i<vas;i++)grj=grj+s[i];
- grs=grj+s[vas];
- if(grj-difs<0)
- {
- if(grs-difs<=0)
- {
- out<<difs-grj<<" D"<<'\n';
- out<<difs-grs<<" D"<<'\n';
- }
- else
- {
- out<<grs-difs<<" S"<<'\n';
- out<<difs-grj<<" D"<<'\n';
- }
- }
- else
- {
- out<<grs-difs<<" S"<<'\n';
- out<<grj-difs<<" S"<<'\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement