This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
char c, d;
int a, b, n, i, j, k;
long long ans, res, ans2=1e18;
struct st
{
int a, b;
};
vector<st>v;vector<int>v1;
bool cmp(st a, st b)
{
return a.a+a.b<b.a+b.b;
}
main()
{
ios_base::sync_with_stdio(!cin.tie(NULL));
for(cin>>k>>n;i++<n;)
{
cin>>c>>a>>d>>b;
if(c==d)ans+=abs(b-a);
else if(k==2)ans++,v.push_back({a, b});
else ans++,v1.push_back(a),v1.push_back(b);
}
if(k==1)
{
sort(v1.begin(), v1.end());
for(i=0;i<v1.size()/2;i++)ans-=v1[i];
for(i=v1.size()/2;i<v1.size();i++)ans+=v1[i];
cout<<ans;return 0;
}
sort(v.begin(), v.end(), cmp);
for(i=0;i<=v.size();i++)
{
vector<int>V;res=0;
for(j=0;j<i;j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
V.clear();
for(j=i;j<v.size();j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
ans2=min(ans2, res);
}
cout<<ans+ans2;
}
Compilation message (stderr)
bridge.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^
bridge.cpp: In function 'int main()':
bridge.cpp:29:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(i=0;i<v1.size()/2;i++)ans-=v1[i];
| ~^~~~~~~~~~~~
bridge.cpp:30:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(i=v1.size()/2;i<v1.size();i++)ans+=v1[i];
| ~^~~~~~~~~~
bridge.cpp:34:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(i=0;i<=v.size();i++)
| ~^~~~~~~~~~
bridge.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:43:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
bridge.cpp:45:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(j=i;j<v.size();j++)
| ~^~~~~~~~~
bridge.cpp:50:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:51:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |