I was trying to solve this problem: http://ift.tt/1RroqtU
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define LL long long
#define M 1000000007LL
using namespace std;
int T,n,m;
LL cc;
struct Cut{
int dir;
LL cost;
Cut(const int& dir, const LL& cost): dir(dir), cost(cost){}
Cut(){}
bool operator<(const Cut& cut) const
{
return this->cost >= cut.cost;
}
};
vector<Cut> c;
int main() {
cin >> T;
while(T--){
cin >> n >> m;
LL ans = 0, cnt[2] = {0};
c.clear();
for(int i=0; i<n-1; i++) cin >> cc, c.push_back(Cut(0, cc));
for(int i=0; i<m-1;i++) cin >> cc, c.push_back(Cut(1, cc));
sort(c.begin(), c.end());
for(int i=0; i<c.size(); i++){
cout << c[i].cost << endl;
}
cout << "END" << endl;
for(Cut x : c){
(ans += x.cost*(1+cnt[!x.dir]))%=M;
cnt[x.dir]++;
}
cout << ans << endl;
}
return 0;
}
I have such a C++ code which consumes input from std I/O
I have added a loop to output the vector objects' cost property. Now for the following input:
2
83 99
24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
99 49
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
The second test case does not have cost with 24 (only the first test case has 24) But if you run the code, you will find that the vector contains Cut object with cost 24 after sort()!
Why is this happening and how can I solve it?
Aucun commentaire:
Enregistrer un commentaire