Submission #483154

#TimeUsernameProblemLanguageResultExecution timeMemory
483154kawaiiCake 3 (JOI19_cake3)C++17
0 / 100
2 ms588 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long int n, m, v[1000005], c[1000005], ans = 0; struct num{ int diff, V, C; num(); num(int A, int B, int D){ diff = A, V = B, C = D; } }; bool operator < (num a, num b){ return a.diff < b.diff; } vector<num> vec; vector<int> p; void solve(){ sort(vec.begin(), vec.end()); for(int i = vec.size() - 1; i >= vec.size() - m; i--){ ans += vec[i].V; p.push_back(vec[i].C); } sort(p.begin(), p.end()); for(int i = 0; i < p.size(); i++){ if(i == 0) ans -= abs(p[i] - p.back()); else ans -= abs(p[i] - p[i - 1]); } cout << ans; } signed main(){ freopen("cake3.inp", "r", stdin); freopen("cake3.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> v[i] >> c[i]; vec.push_back(num(v[i] - c[i], v[i], c[i])); } solve(); }

Compilation message (stderr)

cake3.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("unroll-loops")
      | 
cake3.cpp: In function 'void solve()':
cake3.cpp:24:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   24 |     for(int i = vec.size() - 1; i >= vec.size() - m; i--){
      |                                 ~~^~~~~~~~~~~~~~~~~
cake3.cpp:29:22: 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(int i = 0; i < p.size(); i++){
      |                    ~~^~~~~~~~~~
cake3.cpp: In function 'int main()':
cake3.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("cake3.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("cake3.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...