Atcoder Beginner Contest 247 D - Cylinder Solution
Problem Link: https://atcoder.jp/contests/abc247/tasks/abc247_d
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
deque<pair<int,int>>q;
int main()
{
long long t,op,sum,f,s,x,c;
cin>>t;
while(t--)
{
cin>>op;
sum=0;
if(op==1)
{
cin>>x>>c;
q.push_back(make_pair(x,c));
}
else
{
cin>>c;
while(c>0)
{
if(q.front().se==c)
{
sum+=(ll)c*q.front().fi;
c=0;
q.pop_front();
}
else if(c>q.front().se)
{
sum+=(ll)q.front().se*q.front().fi;
c-=q.front().se;
q.pop_front();
}
else //c<se
{
sum+=(ll)c*q.front().fi;
q.front().se-=c;
c=0;
}
}
cout<<sum<<endl;
}
}
}
No comments