Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define PPB pop_back
#define MK make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;
constexpr int INF = 1LL << 61;
//constexpr int MOD = 1000000007;
//constexpr int MAX_N = 55;
int n, m;
vector<int> hoge;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
if (n <= a) continue;
hoge.PB(n - a);
}
sort(ALL(hoge));
int ans = 0;
for (int i = 0; i < hoge.size() - 1; ++i) ans += hoge[i];
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment