Comments
On MobinteymooriQuestion 158B taxi, 11 years ago
0

I don't know if you've already solve this problem; Else, here is one solution. You just have to store all groups in an array. And , sort it increasingly. Then, the solution becomes more obviously.

#include <bits/stdc++.h>
#define in cin>>
#define out cout<<
#define M 100002
#define FOR(i,k,l)   for(int i(k); i<l; i++)
#define Si set<int>
#define Mii map<int,int>
#define Mss map<string,string>
#define Vi vector<int>
#define Di deque<int>





using namespace std;

int main(){
ios_base::sync_with_stdio(false);
int n,taxi=0;
    in(n);
    Vi v(M);

    FOR(i,0,n){
        in(v[i]);
    }
    sort(v.begin(),v.end());

        int i=v.size()-1;
        int k=0;
        while(k!= i){
            if(v[i]+ v[k]<=4){
                v[i]+=v[k];
                k++;
            }
            else{
                i--;
                taxi++;
            }
        }
    out(taxi+1);


return 0;
}

Please, I need help on problem D,

I get an runtime error: Here is my source code:

Please, can anybody help me? I got an "runtime error" with problem D, which seems a very simple problem at first. I don't rellay understrand where's the wrong ~~~~~

#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <time.h>
#define pi acos(-1.0)
#define E 2.71828182845904523536
#define  FOR(i,k,n) for(int i(k); i<n;i++)
#define wh(i,k) while(i<k)
#define M 100002

using namespace std;

long long domino[M][2];

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
long long m,n;
    memset(domino,-1,sizeof(domino));
        domino[1][0]=0;
        domino[1][1]=0;
        long long size=2;
    cin>>t;
    FOR(k,1,t+1){
        cin>>n>>m;
        if(domino[m][0] != -1)
            cout<<"Case "<<k<<": "<<domino[m][0]<<" "<<domino[m][1]<<endl;
        else{
            for(long long i=size; i<=m; i++){
                if(domino[i-1][0] == domino[i-1][1]){
                    domino[i][0]=domino[i-1][0]+1;
                    domino[i][1]=0;
                    cout<<domino[i][0]<<" "<<domino[i][1]<<endl;
                    size++;
                }
                else{
                    domino[i][0]=domino[i-1][0];
                    domino[i][1]= domino[i-1][1] + 1;
                    cout<<domino[i][0]<<" "<<domino[i][1]<<endl;
                    size++;
                }
            }
            cout<<"Case "<<k<<": "<<domino[m][0]<<" "<<domino[m][1]<<endl;

        }
    }





return 0;
}

~~~~~

thankx alot. I just realised I've tried the bad dp solution.

Please, can anybody help me with problem C? I got a time limit exceeded, here's my code:

#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <time.h>
#define pi acos(-1.0)
#define E 2.71828182845904523536
#define  FOR(i,k,n) for(int i(k); i<n;i++)

#define M 10005
using namespace std;
map <int, int> items;
int nbrSacs,temp;
unsigned long long dpMatrix[M]; //dpMatrix[i] contains the sum of amusement of types 1,2...i
unsigned long long maxi;

int main(){

int t,n,m,c;
    cin>>t;
    FOR(k,0,t){
        int id;
        cin>>m>>n>>c;

        memset(dpMatrix,0,sizeof(dpMatrix));
        items.clear();
        FOR(j,0,m){
            cin>>id;
            items[id]++; //Item is a map which is in form " items[type]= numbers of items of that type"
        }


        maxi=0;
        FOR(i,1,n+1){
            FOR(j,i,n+1){
                if(i==j){
                    dpMatrix[i]=(i*i)%c;;
                    nbrSacs= items[i];
                    maxi=max(nbrSacs*dpMatrix[i],maxi);
                }
                else{
                    dpMatrix[j]=((j*j)%c)+dpMatrix[j-1];
                    nbrSacs=min(nbrSacs, items[j]);
                    maxi=max(maxi, nbrSacs*dpMatrix[j]);
                }
            }
        }
        cout<<"Case "<<k+1<<": "<<maxi<<endl;

    }

return 0;
}

Can anybody help me please? With problem c (giveaways) I got a time limit exceeded with this code, and I don't really see how to improve my algorithm complexity.

#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <time.h>
#define pi acos(-1.0)
#define E 2.71828182845904523536
#define  FOR(i,k,n) for(int i(k); i<n;i++)

#define M 10005
using namespace std;
map <int, int> items;
int nbrSacs,temp;
unsigned long long dpMatrix[M]; //dpMatrix[i] contains the sum of amusement of types 1,2...i
unsigned long long maxi;

int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
int t,n,m,c;
    cin>>t;
    FOR(k,0,t){
        int id;
        cin>>m>>n>>c;

        memset(dpMatrix,0,sizeof(dpMatrix));
        items.clear();
        FOR(j,0,m){
            cin>>id;
            items[id]++; //Item is a map which is in form " items[type]= numbers of items of that type"
        }


        maxi=0;
        FOR(i,1,n+1){
            FOR(j,i,n+1){
                if(i==j){
                    dpMatrix[i]=(i*i)%c;;
                    nbrSacs= items[i];
                    maxi=max(nbrSacs*dpMatrix[i],maxi);
                }
                else{
                    dpMatrix[j]=((j*j)%c)+dpMatrix[j-1];
                    nbrSacs=min(nbrSacs, items[j]);
                    maxi=max(maxi, nbrSacs*dpMatrix[j]);
                }
            }
        }
        cout<<"Case "<<k+1<<": "<<maxi<<endl;

    }

return 0;
}