Advertisement
TAHMID37

Lab_task_190041237__2.0(2)

Oct 4th, 2020 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.92 KB | None | 0 0
  1. //Task 1
  2. /*  TAHMID RAHMAN
  3.     DAMIAN FOREVER
  4.      MATH LOVER
  5.     NEVER GIVE UP
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. #define pi acos(-1.0)
  10. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  11. #define ll long long
  12. #define pb push_back
  13. #define fi first
  14. #define se second
  15. #define in insert
  16. #define mp make_pair
  17. #define GCD(a,b) __gcd(a,b);
  18. #define endl "\n"
  19. #define FRU freopen("out.txt","w",stdout)
  20. #define FRO freopen("in.txt","r",stdin)
  21. #define INFLL 9223372036854775807
  22. #define debug 0
  23. #define MAXN   100001
  24. #define ar array
  25. const int mxN=2e5;
  26. const int MOD=1e9+7;
  27. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  28. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  29. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  30. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  31. int main()
  32. {
  33.     fastio;
  34.     ll n,i,x,j;
  35.     cin>>n;
  36.     vector<ll>v(n);
  37.     bool ok=true;
  38.     ll prev=0;
  39.     for(i=0;i<n;i++)
  40.     {
  41.         cin>>x;
  42.         v[i]=x;
  43.         if(prev>x)
  44.         {
  45.             ok=false;
  46.         }
  47.         prev=x;
  48.     }
  49.  
  50.     if(ok)
  51.     {
  52.         cout<<"Yes"<<endl;
  53.         return 0;
  54.     }
  55.  
  56.     cout<<"NO"<<endl;
  57.  
  58.     //debugx(v);
  59.  
  60.     for(i=0;i<n-1;i++)
  61.     {
  62.         for(j=0;j<n-i-1;j++)
  63.         {
  64.             if(v[j]>v[j+1])
  65.                 swap(v[j],v[j+1]);
  66.         }
  67.         //debugx(v);
  68.     }
  69.  
  70.     for(auto x:v)
  71.     {
  72.         cout<<x<<" ";
  73.     }
  74.     cout<<endl;
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82. //Task 2
  83.  
  84. /*  TAHMID RAHMAN
  85.     DAMIAN FOREVER
  86.      MATH LOVER
  87.     NEVER GIVE UP
  88. */
  89. #include<bits/stdc++.h>
  90. using namespace std;
  91. #define pi acos(-1.0)
  92. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  93. #define ll long long
  94. #define pb push_back
  95. #define fi first
  96. #define se second
  97. #define in insert
  98. #define mp make_pair
  99. #define GCD(a,b) __gcd(a,b);
  100. #define endl "\n"
  101. #define FRU freopen("out.txt","w",stdout)
  102. #define FRO freopen("in.txt","r",stdin)
  103. #define INFLL 9223372036854775807
  104. #define debug 0
  105. #define MAXN   100001
  106. #define ar array
  107. const int mxN=2e5;
  108. const int MOD=1e9+7;
  109. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  110. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  111. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  112. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  113. int main()
  114. {
  115.     fastio;
  116.     ll t;
  117.     cin>>t;
  118.     while(t--)
  119.     {
  120.         ll n,i,j,m;
  121.         cin>>n>>m;
  122.         vector<ll>v(n);
  123.         for(i=0;i<n;i++)
  124.         {
  125.             cin>>v[i];
  126.         }
  127.         ll x=(n-m);
  128.  
  129.         for(i=0;i<n-1;i++)
  130.         {
  131.             for(j=0;j<n-1-i;j++)
  132.             {
  133.                 if(v[j]>v[j+1])
  134.                 {
  135.                     swap(v[j],v[j+1]);
  136.                 }
  137.             }
  138.         }
  139.  
  140.         //debugx(v);
  141.  
  142.         vector<ll>priffix_sum;
  143.         priffix_sum.pb(0);
  144.         ll sum=0;
  145.         for(i=1;i<=n;i++)
  146.         {
  147.             sum+=v[i-1];
  148.             priffix_sum.pb(sum);
  149.         }
  150.  
  151.        // debugx(priffix_sum);
  152.  
  153.         ll max_sum=priffix_sum[n]-priffix_sum[n-x];
  154.         ll min_sum=priffix_sum[x];
  155.  
  156.         //cout<<max_sum<<" "<<min_sum<<endl;
  157.  
  158.        cout<<max_sum-min_sum<<endl;
  159.  
  160.     }
  161. }
  162.  
  163.  
  164.  
  165.  
  166. //Task 3
  167.  
  168. /*  TAHMID RAHMAN
  169.     DAMIAN FOREVER
  170.      MATH LOVER
  171.     NEVER GIVE UP
  172. */
  173. #include<bits/stdc++.h>
  174. using namespace std;
  175. #define pi acos(-1.0)
  176. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  177. #define ll long long
  178. #define pb push_back
  179. #define fi first
  180. #define se second
  181. #define in insert
  182. #define mp make_pair
  183. #define GCD(a,b) __gcd(a,b);
  184. #define endl "\n"
  185. #define FRU freopen("out.txt","w",stdout)
  186. #define FRO freopen("in.txt","r",stdin)
  187. #define INFLL 9223372036854775807
  188. #define debug 0
  189. #define MAXN   100001
  190. #define ar array
  191. const int mxN=2e5;
  192. const int MOD=1e9+7;
  193. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
  194. {
  195.     return (a.second < b.second);
  196. }
  197. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  198. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  199. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  200. int main()
  201. {
  202.     fastio;
  203.     ll t;
  204.     t=1;
  205.     //cin>>t;
  206.     while(t--)
  207.     {
  208.         ll n,i;
  209.         cin>>n;
  210.  
  211.         vector<ll>v(n);
  212.         ll max_num=-1;
  213.  
  214.         for(i=0;i<n;i++)
  215.         {
  216.             cin>>v[i];
  217.             max_num=max(max_num,v[i]);
  218.         }
  219.  
  220.         ll a[max_num+1]={0};
  221.  
  222.         for(i=0;i<n;i++)
  223.         {
  224.             a[v[i]]=i;
  225.         }
  226.  
  227.         for(i=0;i<n-1;i++)
  228.         {
  229.             for(ll j=0;j<n-1-i;j++)
  230.             {
  231.                 if(v[j]>v[j+1])
  232.                     swap(v[j],v[j+1]);
  233.             }
  234.         }
  235.  
  236.         for(i=0;i<n;i++)
  237.         {
  238.             cout<<a[v[i]]<<" ";
  239.         }
  240.         cout<<endl;
  241.  
  242.     }
  243. }
  244.  
  245.  
  246.  
  247.  
  248.  
  249. //Task 4
  250.  
  251. /*  TAHMID RAHMAN
  252.     DAMIAN FOREVER
  253.      MATH LOVER
  254.     NEVER GIVE UP
  255. */
  256. #include<bits/stdc++.h>
  257. using namespace std;
  258. #define pi acos(-1.0)
  259. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  260. #define ll long long
  261. #define pb push_back
  262. #define fi first
  263. #define se second
  264. #define in insert
  265. #define mp make_pair
  266. #define GCD(a,b) __gcd(a,b);
  267. #define endl "\n"
  268. #define FRU freopen("out.txt","w",stdout)
  269. #define FRO freopen("in.txt","r",stdin)
  270. #define INFLL 9223372036854775807
  271. #define debug 0
  272. #define MAXN   100001
  273. #define ar array
  274. const int mxN=2e5;
  275. const int MOD=1e9+7;
  276. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  277. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  278. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  279. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  280. int main()
  281. {
  282.     fastio;
  283.     ll n,k,i,x;
  284.     cin>>n>>k;
  285.     ll c=0;
  286.     for(i=0;i<n;i++)
  287.     {
  288.         cin>>x;
  289.         if((5-x)>=k)
  290.         {
  291.             c++;
  292.         }
  293.     }
  294.     cout<<(c/3)<<endl;
  295. }
  296.  
  297.  
  298.  
  299. //Task 5
  300.  
  301. /*  TAHMID RAHMAN
  302.     DAMIAN FOREVER
  303.      MATH LOVER
  304.     NEVER GIVE UP
  305. */
  306. #include<bits/stdc++.h>
  307. using namespace std;
  308. #define pi acos(-1.0)
  309. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  310. #define ll long long
  311. #define pb push_back
  312. #define fi first
  313. #define se second
  314. #define in insert
  315. #define mp make_pair
  316. #define GCD(a,b) __gcd(a,b);
  317. #define endl "\n"
  318. #define FRU freopen("out.txt","w",stdout)
  319. #define FRO freopen("in.txt","r",stdin)
  320. #define INFLL 9223372036854775807
  321. #define debug 0
  322. #define MAXN   100001
  323. #define ar array
  324. const int mxN=2e5;
  325. const int MOD=1e9+7;
  326. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
  327. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  328. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  329. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  330.  
  331. struct stu
  332. {
  333.     string name;
  334.     ll data_structure;
  335.     ll networking;
  336.     ll machine_learning;
  337.     ll total_marks;
  338.  
  339. };
  340.  
  341. bool comp(stu x , stu y)
  342. {
  343.  
  344.     if(x.total_marks!=y.total_marks)
  345.         return x.total_marks>y.total_marks;
  346.  
  347.     if(x.machine_learning!=y.machine_learning)
  348.         return x.machine_learning>y.machine_learning;
  349.  
  350.     return x.data_structure>y.data_structure;
  351.  
  352. }
  353.  
  354.  
  355. int main()
  356. {
  357.     ll n,i;
  358.     cin>>n;
  359.  
  360.     stu a[n];
  361.  
  362.     for(i=0;i<n;i++)
  363.     {
  364.         cin>>a[i].name;
  365.         cin>>a[i].machine_learning;
  366.         cin>>a[i].data_structure;
  367.         cin>>a[i].networking;
  368.  
  369.         a[i].total_marks=a[i].data_structure+a[i].networking+a[i].machine_learning;
  370.     }
  371.  
  372.  
  373.     sort(a,a+n,comp);
  374.  
  375.  
  376.     for(i=0;i<n;i++)
  377.     {
  378.         cout<<i+1<<" "<<a[i].name<<endl;
  379.  
  380.     }
  381.  
  382.  
  383. }
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement