Submission #746980

#TimeUsernameProblemLanguageResultExecution timeMemory
746980nguyentunglamCake 3 (JOI19_cake3)C++17
5 / 100
4101 ms340 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
pair<int, int> a[N];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1, [] (const ii &x, const ii &y) {
         return x.se < y.se;
         });
    long long ans = -1e18;
//    for(int i = 1; i <= n; i++) cout << a[i].fi << " " << a[i].se << endl;
    for(int i = 1; i <= n; i++) for(int j = i + m - 1; j <= n; j++) {
        vector<int> lst;
        for(int k = i + 1; k <= j - 1; k++) lst.push_back(a[k].first);
        sort(lst.begin(), lst.end(), greater<int>());
        long long tmp = a[i].first + a[j].first;
        for(int k = 0; k < m - 2; k++) tmp += lst[k];
        ans = max(ans, tmp - (a[j].second - a[i].second) * 2);
    }
    cout << ans;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:13:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...