Skip to main content

Posts

Showing posts from June, 2018

Makx Sum: KSUBSUM

Problem Link #include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #define sf(i) scanf("%d",&i) #define pf(i) printf("%d ", i) using namespace std; const int N = 10000; int main() {     int t, n, k1, k2, k3;     int arr[N + 1];     int sum[2015];     int index;     long s, val;     sf(t);     while(t--)     {         sf(n), sf(k1), sf(k2), sf(k3);         priority_queue<long, vector<long>, greater<long>> pq;         index = 0;         s = 0;         for(int i = 0; i < n; i++)         {             sf(arr[i]);         }         for(int i = 1; i < n; i++)         {            arr[i] += arr[i - 1];         }         for(int i = 0; i < n; i++)         {             for(int j = i; j < n; j++)             {                 if(i == 0)                 {                     val = arr[j];                 }                

Mahesh and his lost array: ANUMLA

Problem Link #include <iostream> #include <set> #include <cstring> #include <algorithm> using namespace std; #define ll long long const int N = 32768; int main() {     int n, t;     long long arr[N + 1];         cin >> t;     while(t--)     {         cin >> n;         multiset<ll> s;         long long sum[N + 1];         long long element[N + 1];         int maxIndex = 1 << n;         for(int i = 0; i < maxIndex; i++)         {             cin >> arr[i];         }         sort(arr, arr + maxIndex);         if(n == 1)         {             cout << arr[1] << endl;             continue;         }         if(n == 2)         {             cout << arr[1] << " " <<  arr[2] << endl;             continue;         }         int index = 0;         int sumIndex = 0;         for(int i = 1; i < maxIndex; i++)         {             int expected

IPC Trainers : IPCTRAIN

Problem Link #include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <set> using namespace std; const int N = 1e5; struct node {     int trainer;     int day;     int sadness;     node()     {     }     node(int t, int d, int s)     {         trainer = t;         day = d;         sadness = s;     } }; bool comparator(node a, node b) {     return a.sadness > b.sadness; } int main() {     long long result;     int test, n, D, d, t, s;     int freq[N + 1], sad[N + 1];     vector<node> v;     node temp;     cin >> test;     while(test--)     {         cin >> n >> D;         memset(freq, 0, sizeof freq);         memset(sad, 0, sizeof sad);         result = 0;         v.clear();         set<int> daySet;         for (int i = 0; i < D; i++) { daySet.insert(i); }         for(int i = 0; i < n; i++)         {             cin >>

Field Trip-FTRIP

Problem Link #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 1001; double ncr[N][N]; void calNCR() {     for(int i = 0; i < N; i++)     {         for(int j = 0; j < N; j++)             ncr[i][j] = 0;     }     for(int i = 0; i < N; i++)     {         ncr[i][0] = ncr[i][i] = 1.0;         for(int j = 1; j < i; j++)         {             ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];         }     } } int main() {     int t, s, n, m, k;     calNCR();     cin >> t;     for(int j = 0; j < t; j++)     {         cin >> s >> n >> m >> k;         double den = ncr[s - 1][n - 1];         double num = 0;         /* if s = 6, m = 4, n = 4, k = 1. Here 2 people from m will go to the trip for sure.            One of them is Alice, so one more friend will picked up for sure. So we should start checking              probability of picking from 2(mc2) be